private void ManageState() {
var nextStates = state.GetNextStates();
for (int index = 0; index < nextStates.Length; index++)
{
if (Input.GetKeyDown(KeyCode.Alpha1 + index))
{
state = nextStates[index];
textBlock.text = state.GetStoryState();
}
}
}
So this is our code.
At the very first loop, index = 0. Since we’re at starting state, the length of the array is 1(or 0?), therefore 0<1.
Then we can only press “1” key, which will be the only key to react and set our “state” variable to 0, which is the first and only option. (key 1)
Then I am completely lost and felt lost during that lecture.
So I have a couple of questions of my own.
-
Lets say the length of the array is 1, so it has 2 elements in it.
nextStates.Length equals to what? the amount of elements within the state or the array length of the state? -
We get to our next state, what is our index equals to? 1 or 0?
I am confused because Rick said every time we loop through the “for”, index is set to 0… so in my mind what I understood was because we wrote the code where it updates every frame, this means ManageState() method is called every frame? which leads to index being continuously set to 0?
I still have more questions to ask but they depend on your answers so I’ll wait.