Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
/ fsm Public archive

Simple Finite State Machine for Unity3D

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

coinflipgamesllc/fsm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSM

Simple finite state machine for Unity

Usage

using CoinFlipGames.FSM;
using System;
using UnityEngine;

public class MyMonoBehaviour : MonoBehaviour
{
	// Set in the inspector!
	public StateMachine stateMachine;

	private enum States
	{
		Start,
		Player1Turn,
		Player2Turn,
		Player1Win,
		Player2Win
	}

	void Start ()
	{
		// First state becomes the default and runs automatically
		stateMachine.AddState(
			States.Start,
			(previous) => { Debug.Log ("Start.OnEnter"); }, // Can use lambda functions
			() => { Debug.Log ("Start.OnUpdate"); },
			(next) => { Debug.Log ("Start.OnExit"); }
		);

		stateMachine.AddState(
			States.Player1Turn,
			this.StartPlayer1Turn, // Or plain functions as long as they match Action<Enum>
			...
		);
	}

	private void StartPlayer1Turn (Enum previous)
	{
		Debug.Log ("Player1Turn.OnEnter");
	}
}

About

Simple Finite State Machine for Unity3D

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages