So I have been going through the course and have done the for loop as seen below. What I want to do is either use my return / enter key as well for options within my game. So basically I want to null element zero preferably as this would just look nicer when there is no state set to it and make elements 1 and up my for loop. I have tried many different ways and even tried making say element 3 or 4 my return option as well and I keep getting the Object reference not set to a instance error when a incorrect key is pressed. I have included the code and screenshots of what I am talking about.
The only way I seen to do this after hours of trying to figure it out on my own was to ad a replica state in element zero, example ( I am in room 2 so I put room 2 in element zero ). This basically just sends me right back to where I am of course and works but is not what I am trying to accomplish. I want to be able to null the key press when there is no state in the element.
Any help is greatly appreciated.
private void ManageState()
{
var nextStates = state.GetNextStates();
for (int index = 0; index < nextStates.Length; index++)
{
if (Input.GetKeyDown(KeyCode.Alpha1 + index))
{
state = nextStates[index];
}
}
textComponent.text = state.GetStateStory();
}
}