I'm getting this issue in Unity even though I've already created the class StateMachine. Here are the scripts in question. The error appears regarding this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestEnemy : MonoBehaviour
{
[SerializeField]
private float turnAngle;
[SerializeField]
private float turnRange;
private float viewAngle;
private float viewDistance;
private float speed;
private float hunger;
private float hungerSpeed;
private float maxHealth;
private List predators;
private List machineStates;
private StateMachine testMachine;
public float health;
// Start is called before the first frame update
void Start()
{
GenerateMachine();
testMachine.Start();
//testIdle = new IdleMovement("Idle Movement", null);
turnRange = 10f;
}
// Update is called once per frame
void Update()
{
turnAngle = Random.Range(-turnRange, turnRange) * Mathf.PerlinNoise(Time.deltaTime, 0);
testMachine.Update();
}
void GenerateMachine()
{
IdleMovement testIdle = new IdleMovement("Test Idle", null, gameObject.transform, turnAngle);
machineStates.Add(testIdle);
testMachine = new StateMachine(machineStates);
}
}
in the same folder, I have the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StateMachine
{
public List machineStates;
public State runningState;
public StateMachine(List machineStates)
{
this.machineStates = machineStates;
}
public void Start()
{
StartingRunningState();
}
public void Update()
{
runningState.Update();
EvaluateNextState();
}
public void StartingRunningState()
{
foreach (State state in machineStates)
{
if (state.nodeStatus == NodeStatus.RUNNING)
{
runningState = state;
}
}
}
protected void EvaluateNextState()
{
foreach (State nextState in runningState.possibleStates)
{
if (nextState.nodeStatus == NodeStatus.SUCCESS && nextState.priority > runningState.priority)
{
runningState = nextState;
}
}
}
public void StateDebug()
{
string CurrentRunningState()
{
return runningState.nodeName;
}
string NextPossibleStates()
{
string nextPossibleStates = "";
for (int i = 0; i < runningState.possibleStates.Count; i++)
{
if (i == 0)
{
nextPossibleStates += runningState.possibleStates[i];
} else
{
nextPossibleStates += ", " + runningState.possibleStates[i];
}
}
return nextPossibleStates;
}
}
}
Please help I don't understand why I'm getting this issue :(
↧