📜  Unity 让一个 2D 对象看鼠标位置 - C# 代码示例

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

代码示例2
public class LookAtMouse : MonoBehaviour
{
    void Update()
    {
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        
        Vector2 direction = mousePosition - transform.position;
        float angle = Vector2.SignedAngle(Vector2.right, direction);
        transform.eulerAngles = new Vector3 (0, 0, angle);
    }
}