我正在使用Unity 3D创建一个2D旋转旋钮,我设法通过以下代码实现旋转:
var speed = 5f;
Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - 90f;
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed * Time.deltaTime);
现在我想将旋钮限制在0到270度之间。我怎样才能做到这一点?