Unity_物体对象跟随鼠标移动360°旋转
/// <summary> /// 对象旋转跟随鼠标移动 /// </summary> public void ObjectRotateFollowMouseMove() { if(Input.GetMouseButtonDown(0)) { lastMousePoint = Input.mousePosition; } else if(Input.GetMouseButton(0)) { var newMousePoint = Input.mousePosition; var delta = lastMousePoint - newMousePoint; lastMousePoint = newMousePoint; Quaternion rotate = Quaternion.Euler(-delta.y * speed, delta.x * speed, 0); //TODO:可扩展 transform.rotation = rotate * transform.rotation; //四元素相乘是角的累积 } }