You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

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<NavMeshAgent>().SetDestination(player.transform.position);
}
else
{
if (Vector3.Distance(transform.position, targets[index].position) > 0.5f)
{
GetComponent<NavMeshAgent>().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;
}
}
}