I’m trying to create a simple Finite State Machine for the bosses within my game as I want them to have different attacks and randomly switch between them.
This is the script I’ve used for the Finite State Machine:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FSM : MonoBehaviour {
public delegate void State();
private List<State> availableActions = new List<State>();
private State action;
public FSM(State state)
{
action = state;
}
public void AddState(State state)
{
availableActions.Add(state);
}
public void RandomState()
{
SetState(availableActions[Random.Range(0, availableActions.Count)]);
}
public void SetState(State state)
{
action = state;
}
void Update ()
{
action();
}
}
I simply add a method using the AddState() method within a boss class and it will be added to the availableActions list which will be looped through when calling RandomState(). Or I can just use SetState(). Currently it works fine but I’m having to remove one of the actions that my boss has because it’s a coroutine and of course I want to be able to use both types of methods (Voids and Corutines).
This is the error I get: http://i.imgur.com/MWkHeMO.jpg
I know it’s because of the coroutine but is there a way I can make my Finite State Machine work with coroutines also?
Thanks