using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using UnityEngine.UIElements; public class AutoMove : MonoBehaviour { public Transform[] targets; public int index = 0; public GameObject player; public bool b; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (b) { GetComponent().SetDestination(player.transform.position); } else { if (Vector3.Distance(transform.position, targets[index].position) > 0.5f) { GetComponent().SetDestination(targets[index].position); } else { index++; if (index >= targets.Length) { index = 0; } } } } private void OnTriggerEnter(Collider other) { Debug.Log(other.name); if (other.tag == "Player") { b = true; } } private void OnTriggerExit(Collider other) { if (other.tag == "Player") { b = false; } } }