Advertisement
Pro_Unit

LookAtTarget2D

Sep 14th, 2022
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.36 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class LookAtTarget2D : MonoBehaviour
  4. {
  5.     [SerializeField] private Transform _target;
  6.     [SerializeField] private Vector3 _worldUp = Vector3.up;
  7.  
  8.     private void Update()
  9.     {
  10.         Vector2 direction = _target.position - transform.position;
  11.         transform.rotation = Quaternion.FromToRotation(_worldUp, direction);
  12.     }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement