精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學(xué)習(xí)啦>學(xué)習(xí)電腦>電腦硬件知識>鍵盤鼠標(biāo)>

      Unity3d鼠標(biāo)拖拽物體

      時間: 沈迪豪908 分享

        愛學(xué)習(xí)的小伙伴們,可能都有了解過Unity3d ,但是你知道Unity3d 怎么使用鼠標(biāo)拖拽物體嗎?

        Unity3d使用鼠標(biāo)拖拽物體的具體代碼

        //Drag object using mouse

        //editor by faye euler

        //add script components to the collider Object with need to be draging

        //將代碼附加到要被拖拽的collider物體上

        function Update () {

        }

        var screenSpace;

        var offset;

        function OnMouseDown(){

        //translate the cubes position from the world to Screen Point

        //轉(zhuǎn)換對象位置,從世界點(diǎn)到屏幕座標(biāo)

        screenSpace = Camera.main.WorldToScreenPoint(transform.position);

        //calculate any difference between the cubes world position and the mouses Screen position converted to a worldpoint

        //在對象世界座標(biāo)與鼠標(biāo)屏幕座標(biāo)計(jì)算任何不同,轉(zhuǎn)換到世界點(diǎn)上

        offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, screenSpace.z));

        }

        /*

        OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.

        OnMouseDrag is called every frame while the mouse is down.

        */

        function OnMouseDrag () {

        //keep track of the mouse position

        //保持鼠標(biāo)位置追蹤

        var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);

        //convert the screen mouse position to world point and adjust with offset

        //轉(zhuǎn)換屏幕鼠標(biāo)位置到世界點(diǎn),以及通過偏移調(diào)整

        var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;

        //update the position of the object in the world

        //更新物體在世界的位置

        transform.position = curPosition;

        }

      猜你喜歡:

      1.2016程序員跳槽全攻略

      2.2016有什么好玩的手機(jī)游戲

      3.創(chuàng)業(yè),我們的故事

      4.如何從零開始創(chuàng)業(yè)

      5.90后創(chuàng)業(yè)心得

      1997108