It seems to be an out of bounds error so the array you’re trying to access must be valid for example if you only have two choices and you press the third button it’s going to try and access a variable that doesn’t exist. Hope that helps
I’m sure the problems depend on one another. Fix what @Riley_Waldo suggested first.
NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.
State CurrentState;
State Stage;
// Start is called before the first frame update
void Start()
{
CurrentState = StartingState;
textComponent.text = CurrentState.GetStateStory();
// Debug.Log(oddNumbers[4]);
}
// Update is called once per frame
void Update()
{
ManageStates();
/* if (Input.GetKeyDown(KeyCode.T))
{
Debug.Log(weekDays[2]);
}
*/
}
private void ManageStates()
{
var nextStates = CurrentState.GetNextStates();
for (int index = 0; index < nextStates.Length; index++)
{
if (Input.GetKeyDown(KeyCode.Alpha1 + index))
{
CurrentState = nextStates[index];
}
}
/* if (Input.GetKeyDown(KeyCode.A))
{
CurrentState = nextStates[0];
}
else if (Input.GetKeyDown(KeyCode.B))
{
CurrentState = nextStates[1];
}
else if (Input.GetKeyDown(KeyCode.C))
{
CurrentState = nextStates[2];
}
*/
textComponent.text = CurrentState.GetStateStory();
}
}
Here’s the updated one. But still numbers are not working
Okay so your introduction only has one option so it should work if you press A but it you hit B or C it’s trying to access stuff that doesn’t exist. If I remember correctly this problem is fixed later in the lectures but if you want a quick fix now you can just check for null.
Right side. Numeric keyboard. After you asked me this, I tried with the upper side number section and it worked. Then why the right side number section is not working ?
As aforementioned, the Alpha keys refer to the horizontal number keys, not to the numpad. If you want to be able to use the numpad as well, do the following: