using UnityEngine; public class RoamState : BaseState { private bool hasCompletedRoaming = false; private float roamDuration = 2f; private Vector3 currentRoamingPoint = Vector3.zero; private TimerSystem roamTimerSystem = null; public RoamState(AICarDriver aiCarDriver, GameplayManager gameplayManager) : base(aiCarDriver, gameplayManager) { Debug.Log($"### {this} constructor"); } protected override void Enter() { base.Enter(); Debug.Log($"### {this} Enter STAGE"); // get the target point currentRoamingPoint = gameplayManager.GetRoamingPoint(); aiCarDriver.SetTargetPosition(currentRoamingPoint); roamTimerSystem = new TimerSystem(); hasCompletedRoaming = false; roamTimerSystem.Init(roamDuration, onComplete: () => hasCompletedRoaming = true); } protected override void Update() { base.Update(); // keep roaming for a specific duration // use a set of target points which would be placed on the arena, // get one of the target point and then start roaming towards that point. // if an enemy/player is found within a specific radius and in front of- // -the AI then go to the next state after acquiring the target- // -(next state could be ChargeState) // Set Target location if (!hasCompletedRoaming) { roamTimerSystem.UpdateTimer(Time.deltaTime); aiCarDriver.UpdateMovement(); } else { base.Exit(); nextState = new AcquireTargetState(aiCarDriver, gameplayManager); } Debug.Log($"### {this} Update STAGE"); } protected override void Exit() { base.Exit(); Debug.Log($"### {this} Exit STAGE"); } }