GregLeck

Untitled

Mar 23rd, 2022
1,065
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoveToGoal : MonoBehaviour
  6. {
  7.     public float speed = 2.0f;
  8.     public float accuracy = 0.01f;
  9.     public Transform goal;
  10.  
  11.     private void Start()
  12.     {
  13.         transform.LookAt(goal.position);    
  14.     }
  15.  
  16.     private void LateUpdate()
  17.     {
  18.         transform.LookAt(goal.position);
  19.  
  20.         Vector3 direction = goal.position - transform.position;
  21.  
  22.         if (direction.magnitude > accuracy)
  23.         {
  24.             transform.Translate(direction.normalized * speed * Time.deltaTime, Space.World);
  25.         }    
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment