- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
- private Quaternion q;
- private Vector3 mousePos;
- private Vector3 preMousePos;
- private Vector3 modelPos;
- private Vector3 localEluer;
- private bool IsSelect = false;
- private float RotateAngle;
- private float angle;
- public Transform target1;
- void Start()
- {
- modelPos = target1.transform.position;
- angle = localEluer.z;
- target1.transform.localEulerAngles = localEluer;
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- IsSelect = true;
- preMousePos = mousePos = Input.mousePosition;
- }
- if (Input.GetMouseButton(0) && IsSelect)
- {
- IsSelect = true;
- mousePos = Input.mousePosition;
- RotateAngle = Vector3.Angle(preMousePos - modelPos, mousePos - modelPos);
- //print (RotateAngle);
- if (RotateAngle == 0)
- {
- preMousePos = mousePos;
- }
- else
- {
- q = Quaternion.FromToRotation(preMousePos - modelPos, mousePos - modelPos);
- float k = q.z > 0 ? 1 : -1;
- localEluer.z += k * RotateAngle;
- Debug.Log(localEluer.x);
- angle = localEluer.z = Mathf.Clamp(localEluer.z, -36000, 36000);
- target1.transform.localEulerAngles = localEluer;
- preMousePos = mousePos;
- }
- }
- if (Input.GetMouseButtonUp(0))
- {
- IsSelect = false;
- }
- }
复制代码 来自:1320494699 的分享
|
|