PointAtAimTarget.cs 466 B

1234567891011121314151617
  1. using UnityEngine;
  2. public class PointAtAimTarget : MonoBehaviour
  3. {
  4. [Tooltip("This object represents the aim target. We always point toeards this")]
  5. public Transform AimTarget;
  6. void Update()
  7. {
  8. // Aim at the aim target
  9. if (AimTarget == null)
  10. return;
  11. var dir = AimTarget.position - transform.position;
  12. if (dir.sqrMagnitude > 0.01f)
  13. transform.rotation = Quaternion.LookRotation(dir);
  14. }
  15. }