Skip to content

Instantly share code, notes, and snippets.

@Streamweaver
Last active February 7, 2020 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Streamweaver/187b913ed6a90f2a2bdde32579ef29b8 to your computer and use it in GitHub Desktop.
Save Streamweaver/187b913ed6a90f2a2bdde32579ef29b8 to your computer and use it in GitHub Desktop.
An Action State Machine Pattern I like in Unity.
// Got this from Jason Weimann's videos. I like the pattern much better.
// from https://unity3d.college/2017/05/26/unity3d-design-patterns-state-basic-state-machine/
public class Entity: Monobehavior
{
private ActionState _currentState;
private void Update() {
_currentState.Tick();
}
}
// Abstract Class to build real actions from.
public abstract class ActionState
{
protected Entity entity;
public abstract void Tick();
public virtual void OnStateEnter() { }
public virtual void OnStateExit() { }
public ActionState(Entity entity)
{
this.entity = entity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment