36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
namespace Code.Example.Race.Racer.AI
|
|
{
|
|
public class AIRacer : Racer
|
|
{
|
|
[SerializeField] private NavMeshAgent navMeshAgent;
|
|
|
|
public override void SetData(RacerData data)
|
|
{
|
|
Data = data;
|
|
navMeshAgent.angularSpeed = data.angularSpeed;
|
|
navMeshAgent.speed = data.speed;
|
|
}
|
|
|
|
public override void Initialize(List<Transform> waypoints)
|
|
{
|
|
navMeshAgent.isStopped = true;
|
|
|
|
Waypoints = waypoints;
|
|
navMeshAgent.destination = Waypoints[CurrentWaypointIndex].position;
|
|
|
|
CurrentWaypointIndex++;
|
|
}
|
|
public override void StartRacer() => navMeshAgent.isStopped = false;
|
|
public override void StopRacer() => navMeshAgent.isStopped = true;
|
|
public override void NextWaypoint()
|
|
{
|
|
if(CurrentWaypointIndex >= Waypoints.Count) CurrentWaypointIndex = 0;
|
|
|
|
navMeshAgent.destination = Waypoints[CurrentWaypointIndex++].position;
|
|
}
|
|
}
|
|
} |