public class RotationTest : MonoBehaviour
{
private Vector3 startPostion;
private Vector3 endPostion;
private Vector3 currentPostion;
private Vector3 offest;//过程中偏移
private Vector3 finalOffest;//最后偏移量
private float angle;
private bool mouseButtonIsUp;//松开鼠标
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
RotationMethod();
}
private void RotationMethod()
{
if (Input.GetMouseButtonDown(0))
{
startPostion = Input.mousePosition;
currentPostion = Input.mousePosition;
}
if (Input.GetMouseButton(0))
{
offest = Input.mousePosition - currentPostion;
currentPostion = Input.mousePosition;
angle = offest.magnitude;
Debug.Log(angle);
transform.Rotate(Vector3.Cross(offest, Vector3.forward).normalized, angle * Time.deltaTime, Space.World);
}
if (Input.GetMouseButtonUp(0))
{
endPostion = Input.mousePosition;
finalOffest = endPostion - startPostion;
angle = finalOffest.magnitude;
mouseButtonIsUp = true;
}
if (mouseButtonIsUp)
{
transform.Rotate(Vector3.Cross(finalOffest,Vector3.forward).normalized,angle*Time.deltaTime,Space.World);
if (angle > 0)
{
angle -= 6;
}
else
{
angle = 0;
}
}
}
}