Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MoveToGoal : MonoBehaviour
- {
- public float speed = 2.0f;
- public float accuracy = 0.01f;
- public Transform goal;
- private void Start()
- {
- transform.LookAt(goal.position);
- }
- private void LateUpdate()
- {
- transform.LookAt(goal.position);
- Vector3 direction = goal.position - transform.position;
- if (direction.magnitude > accuracy)
- {
- transform.Translate(direction.normalized * speed * Time.deltaTime, Space.World);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment