So I made this code for my Text 101 game, but there are several things that aren’t working:
-Easer Egg: Pressing U in state.stare does not direct you to state.rainbow_unicorn.
-Cabinet: Pressing C in the beginning redirects you to the sink.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class TextController : MonoBehaviour {
public Text text;
private enum States {rainbow_unicorn,cabinet,files,hospital,mirror,sink,stare,cabinet_1a,files_1a,hospital_1a,mirror_1a,sink_1a,stare_1a,cabinet_1b,files_1b,hospital_1b,mirror_1b,sink_1b,stare_1b,cabinet_2,files_2,door,converse};
private States myState;
// Use this for initialization
void Start () {
myState = States.hospital;
}
// Update is called once per frame
void Update () {
print (myState);
if(myState == States.hospital){
state_hospital();
}else if(myState == States.cabinet){
state_sink();
}else if(myState == States.files){
state_files();
}else if(myState == States.mirror){
state_mirror();
}else if(myState == States.sink){
state_sink();
}else if(myState == States.stare){
state_stare();
}
}
void state_hospital (){
text.text = "You wake up in a worn-down hospital room with " +
"cabinets and medical materials. The walls are concrete coal gray, "+
"and a door that locks from the outside, almost like a prison cell.\n\n"+
"Press the respective letter to take action: (C)Cabinet (E)Stare (F)Files (M)Mirror (S)Sink";
if(Input.GetKeyDown(KeyCode.C)){
myState = States.cabinet;
}else if(Input.GetKeyDown(KeyCode.F)){
myState = States.files;
}else if(Input.GetKeyDown(KeyCode.S)){
myState = States.sink;
}else if(Input.GetKeyDown(KeyCode.E)){
myState = States.stare;
}else if(Input.GetKeyDown(KeyCode.M)){
myState = States.mirror;
}
}
void state_cabinet (){
text.text = "You rummage through the cabinets, and find a couple of disorganized papers, some empty vial tubes, and a knife.\n\n"+
"Press the respective letter to take action: (H)Bed (C)Take the knife";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital;
}else if(Input.GetKeyDown(KeyCode.C)){
myState = States.cabinet_1a;
}
}
void state_files (){
text.text = "You inspect the files in the divider. One "+
"particular file catches your attention. It has your "+
"name on it!"+
"\n\n"+
"Press the respective letter to take action: (H)Bed (F)Inspect the files";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital;
}else if(Input.GetKeyDown(KeyCode.F)){
myState = States.files_1b;
}
}
void state_mirror (){
text.text = "You take a short glance at your reflection.\n"+
"You're an Asian American, with white, spiky thick hair that curls and points outward,"+
""+
"\n\n"+
"Press the respective letter to take action: (H)Bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital;
}
}
void state_sink (){
text.text = "You walk over to the cabinet sink which still seems "+
"surprisingly clean, you turn the nozzle on the sink counterclockwise "+
"and it dispenses a soft stream of cold but assuring water. "+
"You wash your water with rejuvinating water, and clean it off with a "+
"nearby towel.\n\n"+
"Press the respective letter to take action: (H)Bed (M)Mirror";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital;
}else if(Input.GetKeyDown(KeyCode.M)){
myState = States.mirror;
}
}
void state_stare (){
text.text = "You... decide to stare blankly at a concrete and grainy wall."+
"What else interesting is there to really observe? What else were you"+
"expecting a rainbow unicorn?"+
"\n\n"+
"Press the respective letter to take action: (H)Bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital;
}else if(Input.GetKeyDown(KeyCode.U)){
myState = States.rainbow_unicorn;
}
}
/// VISUAL DIVIDER
/// From state_cabinet to state_cabinet_1a.
/// VISUAL DIVIDER
void state_cabinet_1a (){
text.text = "You take the knife, and put it in your pocket.\n\n"+
"Press the respective letter to take action: (H)Bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1a;
}
}
void state_hospital_1a (){
text.text = "There are cabinets and medical materials. The walls are concrete coal gray, "+
"and a door that locks from the outside, almost like a prison cell."+
"\n\n"+
"Press the respective letter to take action: (E)Stare (F)Files (S)Sink";
if(Input.GetKeyDown(KeyCode.F)){
myState = States.files_1a;
}else if(Input.GetKeyDown(KeyCode.S)){
myState = States.sink_1a;
}else if(Input.GetKeyDown(KeyCode.E)){
myState = States.stare_1a;
}
}
void state_files_1a (){
text.text = "You inspect the files in the divider. One"+
"particular file catches your attention. It has your"+
"name on it!"+
"\n\n"+
"Press the respective letter to take action: (H)Bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1a;
}else if(Input.GetKeyDown(KeyCode.F)){
myState = States.files_2;
}
}
void state_mirror_1a (){
text.text = "You take a short glance at your reflection.\n"+
"You're an Asian American, with white, spiky thick hair that curls and points outward,"+
""+
"\n\n"+
"Press the respective letter to take action: (H)Bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1a;
}
}
void state_sink_1a (){
text.text = "You walk over to the cabinet sink which still seems "+
"surprisingly clean, you turn the nozzle on the sink counterclockwise "+
"and it dispenses a soft stream of cold but assuring water. "+
"You wash your water with rejuvinating water, and clean it off with a "+
"nearby towel.\n\n"+
"Press the respective letter to take action: (H)Bed (M)Mirror";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1a;
}else if(Input.GetKeyDown(KeyCode.M)){
myState = States.mirror_1a;
}
}
void state_stare_1a (){
text.text = "You... decide to stare blankly at a concrete and grainy wall." +
"What else interesting is there to really observe?" +
"\n\n" +
"Press the respective letter to take action: (H)Bed";
if (Input.GetKeyDown (KeyCode.H)) {
myState = States.hospital;
}
}
//This directs to state_door, where both A and B paths converge back into one.
void state_files_2 (){
text.text = "You inspected the file that contains your profile,"+
"with one inconclusive but important detail: your"+
"'Dnomaid Chance' is just a bunch of question marks."+
"You're not sure what that means, let alone the definition"+
"of Dnomaid."+
"\n\n"+
"Press the respective letter to take action: (D)Door";
if(Input.GetKeyDown(KeyCode.D)){
myState = States.door;
}
}
/// VISUAL DIVIDER
/// From state_files to state_files_1b.
/// VISUAL DIVIDER
void state_files_1b (){
text.text = "You inspected the file that contains your profile,"+
"with one inconclusive but important detail: your"+
"'Dnomaid Chance' is just a bunch of question marks."+
"You're not sure what that means, let alone the definition"+
"of Dnomaid."+
"\n\n"+
"Press the respective letter to take action: (H)bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1b;
}
}
void state_hospital_1b (){
text.text = "There are cabinets and medical materials. The walls are concrete coal gray, "+
"and a door that locks from the outside, almost like a prison cell.\n\n"+
"Press the respective letter to take action: (C)Cabinet (E)Stare (S)Sink";
if(Input.GetKeyDown(KeyCode.C)){
myState = States.cabinet_1b;
}else if(Input.GetKeyDown(KeyCode.S)){
myState = States.sink_1b;
}else if(Input.GetKeyDown(KeyCode.E)){
myState = States.stare_1b;
}
}
void state_cabinet_1b (){
text.text = "You rummage through the cabinets, and find a couple of disorganized papers, some empty vial tubes, and a knife.\n\n"+
"Press the respective letter to take action: (H)Bed (C)Take the knife";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1b;
}
}
void state_mirror_1b (){
text.text = "You take a short glance at your reflection.\n"+
"You're an Asian American, with white, spiky thick hair that curls and points outward,"+
""+
"\n\n"+
"Press the respective letter to take action: (H)Bed";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1b;
}
}
void state_sink_1b (){
text.text = "You walk over to the cabinet sink which still seems "+
"surprisingly clean, you turn the nozzle on the sink counterclockwise "+
"and it dispenses a soft stream of cold but assuring water. "+
"You wash your water with rejuvinating water, and clean it off with a "+
"nearby towel.\n\n"+
"Press the respective letter to take action: (H)Bed (M)Mirror";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital_1b;
}else if(Input.GetKeyDown(KeyCode.M)){
myState = States.mirror_1b;
}
}
void state_stare_1b (){
text.text = "You... decide to stare blankly at a concrete and grainy wall." +
"What else interesting is there to really observe?" +
"\n\n" +
"Press the respective letter to take action: (H)Bed";
if (Input.GetKeyDown (KeyCode.H)) {
myState = States.hospital_1b;
}
}
void state_cabinet_2 (){
text.text = "You take the knife, and put it in your pocket.\n\n"+
"Press the respective letter to take action: (D)Door";
if(Input.GetKeyDown(KeyCode.D)){
myState = States.door;
}
}
void state_door (){
text.text = "You walk towards the door.\n\n"+
"Press the respective letter to take action: (D)Door";
if(Input.GetKeyDown(KeyCode.D)){
myState = States.door;
}
}
void state_converse (){
text.text = "You take the knife, and put it in your pocket.\n\n"+
"Press the respective letter to take action: (D)Door";
if(Input.GetKeyDown(KeyCode.D)){
myState = States.door;
}
}
/// VISUAL DIVIDER
/// Starting from this line and below, are all Easter Eggs.
/// VISUAL DIVIDER
//Discovered by entering state_mirror, then pressing U.
void state_rainbow_unicorn (){
text.text = "HOLY MOTHER OF #### YOU ACTUALLY FOUND A UNICORN!"+
"YOU ACTUALLY FOUND IT! hOW?!?"+
"YOU SIR, ARE CLEARLY NOT IN REALITY!"+
"YOU BETTER PRESS H TO GET BACK IN THE GAME RIGHT NOW!!1!!11!1!!ONE1";
if(Input.GetKeyDown(KeyCode.H)){
myState = States.hospital;
}
}
}
Also this is the story tree I got for it: https://docs.google.com/drawings/d/14XMD_hCzZf5-WTJQTJqpvArV3w9GelHMei2ENr_x7nk/edit?usp=sharing
Solution
I figured it out. I realized I didn’t set up myState properly in void Update (){…}