using System.Collections; using System.Collections.Generic; using UnityEngine; using Pathfinding; using System; public class AImove : MonoBehaviour { public static AImove Instance; Seeker mySeeker => transform.GetComponent(); public List aimPoint; public float speed=20f; public List AIposList; public int AIposInt; void Start() { Instance = this; mySeeker.pathCallback += OnPathComplete; } void Update() { } public void CallAImove() { mySeeker.StartPath(transform.position, AIposList[0].transform.position); } void FixedUpdate() { if (aimPoint != null && aimPoint.Count != 0) { Vector3 dir = (aimPoint[0] - transform.position).normalized; Quaternion rota = Quaternion.LookRotation(aimPoint[0] - transform.position); transform.rotation = Quaternion.Lerp(transform.rotation, rota, 0.1f); transform.position += dir * Time.fixedDeltaTime *10f; if (Vector3.Distance(aimPoint[0], transform.position) <= 0.1f) { aimPoint.RemoveAt(0); } if (aimPoint.Count == 0) { print("抵达位置!"); if (AIposInt == 5) { print("结束!"); } if (AIposInt < 5) { AIposInt++; mySeeker.StartPath(transform.position,AIposList[AIposInt].transform.position); } } } } private void OnPathComplete(Path path) { aimPoint = new List(path.vectorPath); } }