ソースコード
using UnityEngine; public class Player : MonoBehaviour { private void Update() { var screenPos = Camera.main.WorldToScreenPoint( transform.position ); var direction = Input.mousePosition - screenPos; var angle = GetAim( Vector3.zero, direction ); transform.SetLocalEulerAnglesY( -angle + 90 ); } public float GetAim( Vector2 from, Vector2 to ) { float dx = to.x - from.x; float dy = to.y - from.y; float rad = Mathf.Atan2(dy, dx); return rad * Mathf.Rad2Deg; } }
使用例