Advertisement
uurha

Untitled

Sep 11th, 2022 (edited)
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. public class TestMove : MonoBehaviour
  2. {
  3.     [SerializeField] private Transform player;
  4.     [SerializeField] private float moveTime = 10f;
  5.    
  6.     //[EditorButton]
  7.     private void StartFollow()
  8.     {
  9.         StartCoroutine(Move());
  10.     }
  11.  
  12.     private IEnumerator Move()
  13.     {
  14.         var time = 0f;
  15.         while (time <= moveTime)
  16.         {
  17.             var step = (player.position - transform.position) * Mathf.InverseLerp(0, moveTime, time);
  18.             transform.position += step;
  19.             time += Time.deltaTime;
  20.             yield return new WaitForSeconds(Time.deltaTime);
  21.             if (Vector3.Distance(transform.position, player.position) <= Vector3.kEpsilon)
  22.             {
  23.                 yield break;
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement