Hello,
I am having some trouble with my code. When I save it in MonoDevelop and try running it in Unity, I get an error message. I can’t seem to find what I’m doing wrong with my code, so if anyone could take a look at it and give me a suggestion on how to make it work, I’d really appreciate your help! My code is pasted below
Thanks,
J
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 () {
myState = States.cell;
}
// Update is called once per frame
void Update () {
print (myState);
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_sheeets_0 () {
text.text = "You can't believe you sleep in these filthy sheets every night. " +
"It has to be laundry day soon...you can't take prison life any longer " +
"Time to get out of Dodge!\n\n" +
"Press R to Return to roaming your cell" ;
if (Input.GetKeyDown(KeyCode.R)) {
myState = States.cell;
}
}
}