viewers access
abstract class State<ContextType> : MonoBehaviour
CyberPsychosis > StateMachine > State
A baseclass for a state machine. handles methods when starting and stopping a state, and optional related context.
// Create a new State, the context type is a Transform, it can use this in any methods like Update and OnDestroy
public abstract class ExampleBaseState : State<Transform>
{
// Called when switching to this state
protected override void OnStateStart()
{
// Use the Transform context to move whatever object is using this state machine.
context.position += new Vector3(0, 10, 0);
Debug.Log("Started state");
}
// Called when stopping this state
protected override void OnStateStop()
{
Debug.Log("Stopped state");
}
}
| Type | Name | Description |
|---|---|---|
<ContextType> |
context | The context required for the type, like the player or enemy using the state. |
void |
StartState | Will call the code required to correctly start the state |
void |
StopState | Will call the code required to correctly stop the state |