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.
72 lines
1.7 KiB
72 lines
1.7 KiB
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<Seeker>();
|
|
public List<Vector3> aimPoint;
|
|
public float speed=20f;
|
|
|
|
public List<GameObject> 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<Vector3>(path.vectorPath);
|
|
}
|
|
}
|