上代码:
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; //重新记录鼠标的位置 } } }
时间: 2024-10-25 08:29:18