Last active
March 26, 2019 08:59
-
-
Save Indp-Dustin/16df9a39fb02a3a3db5f396c9fb4336f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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