Going through the Text101 course and I’m having a bit of an issue with states switching when keys are pressed. I have all my states connected, and my code matches what’s been done in this lesson. On my intro scene, I press 1 to change scenes, the scene changes for a split second then quits and playmode ends. The only difference in my AdventureGame.CS code is I have debug lines to see if it’ll give any errors. it recognizes the correct key is pressed, but that’s it. Any help would be appreciated.
AdventureGame.cs ManageState called in void Update()
private void ManageState()
{
var nextStates = state.GetNextStates();
if (Input.GetKeyDown(KeyCode.Alpha1))
{
state = nextStates[0];
Debug.Log("1 pressed");
}
else if (Input.GetKeyDown(KeyCode.Alpha2))
{
state = nextStates[1];
Debug.Log("2 pressed");
}
textComponent.text = state.GetNextState();
}
}
and here is my State.cs
[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject
{
[TextArea(10,14)] [SerializeField] string storyText;
[SerializeField] State[] nextStates;
public string GetNextState()
{
return storyText;
}
public State[] GetNextStates()
{
return nextStates;
}
}