using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; [CreateAssetMenu(menuName = "Finite State Machine/Action/Patrol/GetRandomLocation")] public class SetRandomLocation : Action { //This action will set a initial destination to the agent //This action only runs once, since is an entry action on the Patrol State private Vector3 destination; //Execute Action public override void Execute(FSM fsm) { NavMeshAgent agent = fsm.Controller.Agent; Waypoints waypoints = fsm.Controller.Waypoints; //Generates a random index int randomIndex = Random.Range(0, waypoints.WaypointsList.Length); //Sets agent destination to a random waypoint destination = waypoints.WaypointsList[randomIndex].transform.position; agent.destination = destination; } }