Unity 鼠标点击左右移动,人物跟随旋转

1

上代码:

using UnityEngine;

using System.Collections;



public class Test : MonoBehaviour {



    private Vector3 startPosition;      //鼠标按钮的坐标点

    private float x;

    public bool isDown;                 //表示鼠标是否按下

    



    public void OnMouseDown() 

    {

        isDown = true;

        startPosition = Input.mousePosition;

    }



    public void OnMouseUp()

    {

        isDown = false;

    }





    public void Update() 

    {

        if(isDown)

        {

            x = Input.mousePosition.x - startPosition.x;

            this.transform.Rotate(new Vector3(0, -x, 0));           //开始旋转

            startPosition = Input.mousePosition;                    //重新记录鼠标的位置

        }

    }



}

你可能感兴趣的:(unity)