State

abstract class State<ContextType> : MonoBehaviour

CyberPsychosis    >    StateMachine    >    State

Summary

A baseclass for a state machine. handles methods when starting and stopping a state, and optional related context.

Example usage

// 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");
    }
}