Hello all, total beginner here with C# although it reminds me of programming in Basic on the TRS-80 back in the day. OK on to the problem. I have a problem with one of my states and I can’t find it. The compiler finds a problem with the “open” state in line 60 but I cannot figure it out. Is there some syntax thing that I am missing?
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class TextController : MonoBehaviour {
public Text text;
private enum States {room1, writing_desk, door_1, silver_key, note, open, escape}
private States myState;
// Use this for initialization
void Start () {
myState = States.room1;
}
// Update is called once per frame
void Update () {
print (myState);
if (myState == States.room1) {
state_room1 ();
} else if (myState == States.writing_desk) {
state_writing_desk ();
} else if (myState == States.door_1) {
state_door_1 ();
} else if (myState == States.silver_key) {
state_silver_key ();
} else if (myState == States.note) {
state_note ();
}else if (myState == States.open) {
state_open ();
}else if (myState == States.escape) {
state_escape ();
}
}
void state_room1 () {
text.text = "You awaken to find yourself on the concrete floor of a room, it is dimmly lit and" +
" cannot be any larger than a 20 foot box. In the center of the room to your right" +
" is a small writing desk. \n\n" +
"Press W to view the WRITING DESK, the number 1 to view the DOOR";
if (Input.GetKeyDown (KeyCode.W)) {
myState = States.writing_desk;
} else if (Input.GetKeyDown (KeyCode.Alpha1)) {
myState = States.door_1;
}
}
void state_door_1 () {
text.text = "A sturdy wooden door. There is nothing special about the door, other than what" +
" looks like a small silver key hole. \n\n" +
"Press W to view the WRITING DESK, R to RETURN, O to open the DOOR with the key.";
if (Input.GetKeyDown (KeyCode.W)) {
myState = States.writing_desk;
} else if (Input.GetKeyDown (KeyCode.R)) {
myState = States.room1;
}else if (Input.GetKeyDown (KeyCode.O)) {
myState = States.open;
}
void state_open () {
text.text = "The rusty lock turns open with a crack and the door begins to swing into the" +
" room with a disconcerting creek. \n\n" +
"Press E to ESCAPE through the DOOR, R to RETURN,";
if (Input.GetKeyDown (KeyCode.W)) {
myState = States.writing_desk;
} else if (Input.GetKeyDown (KeyCode.R)) {
myState = States.room1;
}
}
void state_writing_desk () {
text.text = "One the top of the WRITING DESK you see a small siver key and a note. \n\n" +
"Press K to take the SILVER Key, N to read the NOTE, R to RETURN";
if (Input.GetKeyDown (KeyCode.K)) {
myState = States.silver_key;
} else if (Input.GetKeyDown (KeyCode.R)) {
myState = States.room1;
}else if (Input.GetKeyDown (KeyCode.N)) {
myState = States.note;
}
}
void state_silver_key () {
text.text = "A small silver key with worn teeth. You place it in your INVENTORY \n\n" +
"R to RETURN";
if (Input.GetKeyDown (KeyCode.R)) {
myState = States.room1;
}
}
void state_note () {
text.text = "You unfold a crumpled piece of paper. Written in red on the inside are" +
" the following words... Welcome Mr. Smith I hope you enjoy my game. Solve the" +
" riddles that await you in each space and you will be rewarded. Fail and you" +
" shall perish \n\n" +
"R to RETURN";
if (Input.GetKeyDown (KeyCode.R)) {
myState = States.room1;
}
}
void state_escape () {
text.text = "You walk slowly through the DOOR into the light of day, thankful that" +
" you have survived the ordeal.\n\n" +
"R to RETURN";
if (Input.GetKeyDown (KeyCode.R)) {
myState = States.room1;
}
}
}