Unable to Execute First Loop

I have copied the course’s code directly (except for some whitespace preferences) and I am still unable to execute the first loop in which cell _state changes to sheet_state_0 back to cell_state.
Here is my code:


using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class TextController : MonoBehaviour 
{

	public Text text;

	private enum States {cell, mirror, sheets_0, lock_0, cell_mirror, sheets_1, lock_1, freedom};
	private States myState;

	// Use this for initialization
	void Start () 
	{
		text.text = "Welcome to PRISON!\nYou must escape - Good Luck!\n\n" +
					"(Press Space to Continue)";
		myState = States.cell;
	}
	
	// Update is called once per frame
	void Update () 
	{
		print (myState);
		if (Input.GetKeyDown (KeyCode.Space))
		{
			if (myState == States.cell)
			{
				state_cell();
			}
			else if (myState == States.sheets_0)
			{
				state_sheets_0();
			}
		}	
	}

	void state_cell ()
	{
		text.text = "You are in a prison cell, and you want to escape. There are " +
					"some dirty sheets on the bed, a mirror on the wall, and the door " +
					"is locked from the outside.\n\n" +
					"Press S to view Sheets, M to view Mirror, and L to view Lock.";

		if (Input.GetKeyDown(KeyCode.S)) 
		{
			myState = States.sheets_0;
		}
	}

	void state_sheets_0 ()
	{
		text.text = "You can't beleive you sleep in these things. Surely it's " +
					"time somebody changed them. The pleasures of prison life " +
					"I guess.\n\n" +
					"Press R to return to roaming your cell.";
		if (Input.GetKeyDown(KeyCode.R))
		{
			myState = States.cell;
		}
	}
}

I have tried:
-Closing Unity and MonoScript to retry
-Using a key other than ‘S’ just incase my ‘S’ key was broken or somehow unresponsive
-Checking all braces and ';'s to ensure that there is no obvious error

If anyone sees the flaw in this code please let me know because I’m stumped (I’ve been staring at this for hours) and out of ideas.

Thanks in advance,
OG

You’ve required the user to hold down the space key on every frame in order for the state functions to then run. Try taking that input condition out of the Update loop

Privacy & Terms