using UnityEngine; public class ByPoints : MonoBehaviour { public GameObject[] wayPoint; // в Unity вказати кількість і додати об'єкти int toPoint = 0; // стартова точка public float minDist = 1.0f; public float speed = 0.1f; public bool rand = false; void FixedUpdate() { float dist = Vector3.Distance(gameObject.transform.position, wayPoint[toPoint].transform.position); if (dist > minDist) { Move(); } else { if (rand == false) { if (toPoint + 1 == wayPoint.Length) { toPoint = 0; } else { toPoint++; } } else { toPoint = Random.Range(0, wayPoint.Length); } } } public void Move() { transform.LookAt(wayPoint[toPoint].transform.position); transform.Translate(Vector3.forward * speed); } }