Input.GetKeyDown(KeyCode.S)) line won't work

Please Help me: Everything in the game works fine except this on line of code.

It is the bottom line. I want to push S to go to sheets_1 from cell_mirror.

Please help.

I have even tried to change spelling

Assuming you have no further code beneath that method in your screen shot you are missing a closong curly brace… }

THANK you for responding!! So the brackets were closed.

so the game does run. Every command in the game S,L,M,R works on every screen but when I am in the cell_mirror section only the L works and from there i can finish the game. But when i am in the cell_mirror and try to push S it just freezes.

Thank you again for responding

only the L will work

…for my second guess…

You have spelt all of your methods beginning with states apart from the one you are trying to get to which is state.

If it isnt that it would be useful to ppst your code rather than the screenshot :slight_smile:

ok so i did try to change the spelling but it still didn’t work :disappointed:

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();} 
	else if (myState == States.lock_0) { states_lock_0 ();}
	else if (myState == States.lock_1) { states_lock_1 ();}
	else if (myState == States.lock_1) { states_sheets_1 ();}
	else if (myState == States.mirror) { states_mirror ();}
	else if (myState == States.cell_mirror) { states_cell_mirror ();}
	else if (myState == States.freedom) { states_freedom ();}
}


	
void state_cell () {
	text.text = "You were on a secret mission for the American Goverment, when all of a sudden your plane was shot down. " + 
				"You jumped out right at the right time but the moment you hit the ground, several Nazi's ran to your location " +
				"and shoved their guns right into your face. They started to yell at you in German, as you qucikly put your hands " +
				"behind the back of your head. They carried you away to a prison nearby. 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, Press M to view Mirror, and L to view Lock";
	if (Input.GetKeyDown(KeyCode.S)) 
	{myState = States.sheets_0;}

    else if (Input.GetKeyDown(KeyCode.L))
	{myState = States.lock_0;}

	else if (Input.GetKeyDown (KeyCode.M)) {myState = States.mirror;}

}

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

}
void states_lock_0() {
text.text = “Its locked but I know i can open this some how with what I have in here. It looks like its a combination pad and I can see” +
“peoples fingerprints have been if I look closely at it. \n\n " +
” Press R to Return to roaming your cell";
if (Input.GetKeyDown(KeyCode.R)) {
myState = States.cell;
}
}

void states_lock_1() { 
	text.text = "You stick the mirror through the gate and see the fingerprints and you can open the gate. \n\n " +
			" Press R to Return to roaming your cell or Press O to open the gate";
	if (Input.GetKeyDown(KeyCode.O)) 	{myState = States.freedom;}
	else if (Input.GetKeyDown(KeyCode.R)) {myState = States.cell_mirror;}
}

void states_freedom() {
	text.text = "YOu are free!! \n\n " +
			" Press P to play again ";
	if (Input.GetKeyDown(KeyCode.P)) {
		myState = States.cell;
	}
}

void states_mirror() {
	text.text = "I might be able to use this mirror to escape. \n\n " +
		" Press R to Return to roaming your cell or Press T to take the mirror";
	if (Input.GetKeyDown(KeyCode.R)) { myState = States.cell; }
	else if(Input.GetKeyDown (KeyCode.T)) { myState = States.cell_mirror;}
}

void states_sheets_1() {
	text.text = "I can not do anthing with these sheets and this mirror \n\n " +
			" Press R to Return to roaming your cell";
	if (Input.GetKeyDown(KeyCode.R)) {myState = States.cell_mirror;}
}

void states_cell_mirror() {
	text.text = "I know i can use this mirror to get out of here. \n\n " +
		"Press L to view the lock or Press S to view the sheets";

	if (Input.GetKeyDown(KeyCode.S)) {myState = States.sheets_1 ;}
	else if  (Input.GetKeyDown(KeyCode.L)) {myState = States.lock_1;}
}


	}

I figured it out lol. I feel pretty good right now lol

1 Like

Thank you so much for responding and trying to help me

1 Like

…did you spot the duplicate else if line? :slight_smile:

Yes I did lol

1 Like

hehe, well done… glad you got it sorted :slight_smile:

1 Like

Privacy & Terms