GregLeck

Untitled

Mar 23rd, 2022
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoveLocal : MonoBehaviour
  6. {
  7.     public Transform goal;
  8.     float speed = 0.5f;
  9.     float accuracy = 1.0f;
  10.  
  11.     private void LateUpdate()
  12.     {
  13.         Vector3 lookAtGoal = new Vector3(goal.position.x, this.transform.position.y, goal.position.z);
  14.  
  15.         this.transform.LookAt(lookAtGoal);
  16.  
  17.         if (Vector3.Distance(transform.position, lookAtGoal) > accuracy)
  18.         {
  19.             this.transform.Translate(0, 0, speed * Time.deltaTime);
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment