OOP Implementation in Finite State Machine
Hi.
I'm trying to implement an OOP Finite State Machine for the enemy behaviors. However, I can't seem to find the method to access certain script.
Here are the base scripts
public class FiniteStateMachine : MonoBehaviour {
public List<FSMState> states;
public FSMState initialState;
public FSMState activeState;
void Update()
{
if (activeState == null)
activeState = initialState;
CheckTransisiton();
}
public virtual void CheckTransisiton()
{
foreach (FSMTransition transition in activeState.transitions)
{
if (transition.isValid() == true)
{
activeState.OnExit();
transition.OnTransition();
if (transition.getNextState() != null)
{
activeState = transition.getNextState();
activeState.OnEnter();
}
else
activeState.OnUpdate();
}
}
}
}
public class FSMState : MonoBehaviour {
public virtual void OnEnter() { }
public virtual void OnUpdate() { }
public virtual void OnExit() { }
public List<FSMTransition> transitions;
}
public class FSMTransition : MonoBehaviour {
public virtual bool isValid() { return false; }
public virtual FSMState getNextState() { return null; }
public virtual void OnTransition() { }
}
I created a derived class from FSMState called IdleState, which the enemy will stay idle. The derived class is attached to an empty object. Enemy gameObject has FiniteStateMachine script assigned to it, and the gameObject contains IdleState is assigned to the gameObject FSM state. When in the IdleState, how to i access the enemy alertness, which is a variable at a script attached to enemy gameObject?
Thanks.
Your answer
Follow this Question
Related Questions
Issue with a Class in Finite State Machine 0 Answers
Movement for GameObject[] in arrays jittery when using Lerp in Coroutine 0 Answers
why does my agent keep circling around a previsoulsy set destination? 0 Answers
NullReferenceException in FiniteStateMachine with ThirdPersonCharacter 0 Answers
NavMeshAgent not moving at given speed 0 Answers