Am i doing something wrong orrrrr?

so i made all my code and the game was running fine till i got to corridor_0. i tried to pressed the S key to go to the stairs but letter flashed on the screen for a split second and then it went back to the corridor_0 screen.

when i went back into my code i tried to expand the corridor_0 code by pressing the little plus sign next to it in visual studio 17 and nothing happens. but i see the little “…” next to it indicating that there is in fact more code behind it.

so now that i just went back and looked at it to take the screenshot. I dont even see a plus sign next to it anymore and the “…” has moved down a line for some reason.

any help??

Hi,

Please post your full script instead of the screenshot.


See also;

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

public class TextController : MonoBehaviour
{

    public Text text;
    private enum States
    { cell, mirror, sheets_0, lock_0, cell_mirror, sheets_1, lock_1,
        corridor_0, stairs_0, floor, closet_door, stairs_1, corridor_1, in_closet, stairs_2, corridor_2, corridor_3, courtyard};
    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)
        {
            cell();
        }
        else if (myState == States.mirror)
        {
            mirror();
        }
        else if (myState == States.sheets_0)
        {
            sheets_0();
        }
        else if (myState == States.lock_0)
        {
            lock_0();
        }
        else if (myState == States.cell_mirror)
        {
            cell_mirror();
        }
        else if (myState == States.sheets_1)
        {
            sheets_1();
        }
        else if (myState == States.lock_1)
        {
            lock_1();
        }
        else if (myState == States.corridor_0)
        {
            corridor_0();
        }
        else if (myState == States.floor)
        {
            floor();
        }
        else if (myState == States.closet_door)
        {
            closet_door();
        }
        else if (myState == States.stairs_0)
        {
            stairs_0();
        }
        else if (myState == States.stairs_1)
        {
            stairs_1();
        }
        else if (myState == States.corridor_1)
        {
            corridor_1();
        }
        else if (myState == States.in_closet)
        {
            in_closet();
        }
        else if (myState == States.stairs_2)
        {
            stairs_2();
        }
        else if (myState == States.corridor_2)
        {
            corridor_2();
        }
        else if (myState == States.corridor_3)
        {
            corridor_3();
        }
        else if (myState == States.courtyard)
        {
            myState = States.courtyard;
        }
    }


    void 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;
        }
        else if (Input.GetKeyDown(KeyCode.M))
        {
            myState = States.mirror;
        }
        else if (Input.GetKeyDown(KeyCode.L))
        {
            myState = States.lock_0;
        }
    }
    void mirror()
    {
        text.text = "The dirty old mirror on the wall seems loose.\n\n" +
                    "Press T to Take the mirror, or R to Return to cell";
        if (Input.GetKeyDown(KeyCode.T))
        {
            myState = States.cell_mirror;
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            myState = States.cell;

        }
    }
    void sheets_0()
    {
        text.text = "You can't believe 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;
        }
    }
    void lock_0()
    {
        text.text = "This is one of those button locks. You have no idea what the " +
                    "combination is. You wish you could somehow see where the dirty " +
                    "fingerprints were, maybe that would help.\n\n" +
                    "Press R to Return to roaming your cell";
        if (Input.GetKeyDown(KeyCode.R))
        {
            myState = States.cell;
        }
    }
    void cell_mirror()
    {
        text.text = "You are still in your cell, and you STILL want to escape! There are " +
                    "some dirty sheets on the bed, a mark where the mirror was, " +
                    "and that pesky door is still there, and firmly locked!\n\n" +
                    "Press S to view Sheets, or L to view Lock";
        if (Input.GetKeyDown(KeyCode.S))
        {
            myState = States.sheets_1;
        }
        else if (Input.GetKeyDown(KeyCode.L))
        {
            myState = States.lock_1;
        }
    }
    void sheets_1()
    {
        text.text = "Holding a mirror in your hand doesn't make the sheets look " +
                    "any better.\n\n" +
                    "Press R to Return to roaming your cell";
        if (Input.GetKeyDown(KeyCode.R))
        {
            myState = States.cell_mirror;
        }
    }
    void lock_1()
    {
        text.text = "You carefully put the mirror through the bars, and turn it round " +
                    "so you can see the lock. You can just make out fingerprints around " +
                    "the buttons. You press the dirty buttons, and hear a click.\n\n" +
                    "Press O to Open, or R to Return to your cell";
        if (Input.GetKeyDown(KeyCode.O))
        {
            myState = States.corridor_0;
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            myState = States.cell_mirror;
        }
    }
    void corridor_0()
 void stairs_0()
    {
        text.text = "You open the door to the stairwell, but you hear guards " +
                    "talking upstairs. There seems to be a guard posted" +
                    "on each floor.\n\n" +
                    "Press R to Return";
        if (Input.GetKeyDown(KeyCode.R))
        {
            corridor_0();
        }
    }
    void closet_door()
    {
       text.text = "You try to open the closet door but it's locked\n\n" +
                   "Press R to Return";
        if (Input.GetKeyDown(KeyCode.R))
        {
            corridor_0();
        }
    }
    void floor()
    {
        text.text = "You see something glimmer on the floor not too far from you. " +
                    "You walk over to it. It's a hairpin. Maybe I can use " +
                    "this to unlock the closet door.\n\n" +
                    "Press H to pick up the Hairclip or R to Return";
        if (Input.GetKeyDown(KeyCode.H))
        {
            corridor_1();
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            corridor_0();
        }
    }
    void corridor_1()
    {
        text.text = "You are standing in the corridor with the hairclip " +
                    "in your hand.\n\n" +
                    "Press S to go to Stairs or P to Pick the lock on the closet";
        if (Input.GetKeyDown(KeyCode.S))
        {
            stairs_1();
        }
        else if (Input.GetKeyDown(KeyCode.P))
        {
            in_closet();
        }
    }
    void stairs_1()
    {
        text.text = "You open the door to the stairwell, but you rememeber " +
                    "that there are always gaurds posted here.\n\n" +
                    "Press R to Return";
        if (Input.GetKeyDown(KeyCode.R))
        {
            corridor_1();
        }
    }
    void in_closet()
    {
        text.text = "You see a unused janitor suit.\n\n" +
                    "Press D to Dress or R to Return";
        if (Input.GetKeyDown(KeyCode.D))
        {
            corridor_3();
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            corridor_2();
        }
    }
    void stairs_2()
    {
        text.text = "You open the door to the stairwell to hear guards up the stairs " +
                    "talking, but you notice there are no guards below you.\n\n" +
                    "Press R to Return";
        if (Input.GetKeyDown(KeyCode.R))
        {
            corridor_2();
        }
    }
    void corridor_2()
    {
        text.text = "You are back from the closet to see a stairwell and a exit door. " +
                    "You can exit becuase you have a jumpsuit on and the guards " +
                    "will catch you.\n\n" +
                    "Press B to go Back";
        if (Input.GetKeyDown(KeyCode.B))
        {
            in_closet();
        }
    }
    void corridor_3()
    {
        text.text = "You put the janitor suit on and disposed of your jumpsuit. " +
                    "Now the only thing left to do is walk out the exit " +
                    "door to the courtyard!\n\n" +
                    "Press E to Exit";
        if (Input.GetKeyDown(KeyCode.E))
        {
            myState = States.courtyard;
        }
    }
    void courtayrd()
    {
        text.text = "You see the bright blue sky and feel the hot sun on your skin. " +
                    "You walked straight past the guards and out the front gates. " +
                    "It's a beautiful day to have escaped prison!\n\n" +
                    "Press P to Play again";
       if (Input.GetKeyDown(KeyCode.P))
       {
           corridor_0();
       }
    }
}

Hi,

Just for reference, if you take a look at the linked User Forum Guide, it will show you how to apply code formatting which will make that copy/paste a lot easier to read for those trying to help you. :slight_smile:


Updated Wed Apr 04 2018 19:34

floor is a keyword, you’ll need to rename that to something else in your enum States, perhaps stay consistent and consider floor_0.

The content of your corridor_0 method is missing, scroll down within your pasted code here and you will see, you’ll need to replace that, and with the correct opening/closing curly braces.

Make the above changes and then let me know if you are still having problems, if so, copy/paste your full script again into your reply, with the code formatting please.

but i had the code for corridor_0 and then i clicked the “-” on the left to minimize the code and after i tried to click the “+” sign it didnt open back up

There’s no code in the corridor_0 function! xD

If I had to guess I would say you had it minimised and selected and then possibly either typed over it, or copy/pasted over it.

In any case, it’s missing and needs to be replaced.

You could always copy/paste this from the GameDev.tv GitHub repository if you don’t want to type it back out yourself.

Privacy & Terms