Skip to content

Instantly share code, notes, and snippets.

@Indp-Dustin
Last active March 26, 2019 08:59
Show Gist options
  • Save Indp-Dustin/16df9a39fb02a3a3db5f396c9fb4336f to your computer and use it in GitHub Desktop.
Save Indp-Dustin/16df9a39fb02a3a3db5f396c9fb4336f to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum PlayerState
{
IDLE = 0,
RUN,
CHASE,
ATTACK,
DEAD
}
public class PlayerFSMManager : MonoBehaviour
{
public PlayerState currentState;
public PlayerState startState;
Dictionary<PlayerState, PlayerFSMState> states = new Dictionary<PlayerState, PlayerFSMState>();
private void Awake()
{
states.Add(PlayerState.IDLE, GetComponent<PlayerIDLE>());
states.Add(PlayerState.RUN, GetComponent<PlayerRUN>());
}
private void Start()
{
SetState(startState);
}
public void SetState(PlayerState newState)
{
foreach (PlayerFSMState fsm in states.Values)
{
fsm.enabled = false;
}
states[newState].enabled = true;
currentState = newState;
}
private void Update()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment