首页 > 代码库 > Unity 鼠标点击左右移动,人物跟随旋转

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

技术分享

上代码:

using UnityEngine;using System.Collections;public class Test : MonoBehaviour {    private Vector3 startPosition;      //鼠标按钮的坐标点    private float x;    public bool isDown;                 //表示鼠标是否按下        public void onm ouseDown()     {        isDown = true;        startPosition = Input.mousePosition;    }    public void onm ouseUp()    {        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 鼠标点击左右移动,人物跟随旋转