Hi Rick, I have a little question for you.
I do not know if this is a good programming behavior but instead of using the loop I did what I show in the picture. I declared 4 options in the next state (that is currently the total amount of possible keys that can be pressed in my code), the ones hat I do not want any action when pressed are declared as “none(state)” and is working good, no error is appearing. Is something wrong with this way or can lead to any future problem?
My code:
// Update is called once per frame
void Update()
{
ManageState();
}
private void ManageState()
{
var nextState = state.GetNextState();
if(Input.GetKeyDown(KeyCode.Alpha1))
{
state = nextState[0];
}
else if (Input.GetKeyDown(KeyCode.Alpha2))
{
state = nextState[1];
}
else if (Input.GetKeyDown(KeyCode.Alpha3))
{
state = nextState[2];
}
else if (Input.GetKeyDown(KeyCode.Return))
{
state = nextState[3];
TextComponent.alignment = TextAnchor.MiddleLeft;
}
TextComponent.text = state.GetStateStory();
}