📜  Unity 2D 鼠标看光标 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:45.831000             🧑  作者: Mango

代码示例1
// Note: You should cache Camera.main in Awake()
[SerializeField, Range(0, 50)] private float rotationSpeed = 25.0F;

private void Update()
{
  Vector2 directionDifference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
  float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
  Quaternion targetRotation = Quaternion.AngleAxis(angle, Vector3.forward);
  tranform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime); 

}