[HELP] Script not executing

Hi all,

I am currently doing a course through Udemy, and I have just finished the code for my first game.
I’m unsure why, but when I press play, the code is not executing and I just get a blank screen with nothing on it?

I have uploaded a picture of my Unity editor which may help you make more sense of the issue and I will also include my script…

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

public class TextController : MonoBehaviour {
   
    public Text text;
    private enum States {
        room, door, pillow, wardrobe, door1, completed
    };
    private States myState;
   
    // Use this for initialization
    void Start () {
        myState = States.room;
    }

Please help :frowning:

Hi, yeah of course! -

private States myState;
   
    // Use this for initialization
    void Start () {
        myState = States.room;
    }
   
    void update () {
        print (myState);
        if         (myState == States.room)        {state_room ();}
        else if (myState == States.door)         {state_door ();}
        else if (myState == States.pillow)         {state_pillow ();}
        else if (myState == States.wardrobe)    {state_wardrobe ();}
        else if (myState == States.door1)        {state_door1 ();}
        }
       
    // Update is called once per frame
    void state_room () {
        text.text = "You wake up after hearing a loud bang, what could it be?!" +
                "You look around and you can see the door is closed, the blinds " +
                "are shut and your girlfriend is no longer sleeping next to you.\n\n" +
                "Press 'D' to open the door, Press 'P' to look under your pillow and "+
                "'W' to check the wardrobe.";
        if (Input.GetKeyDown(KeyCode.D)) {myState = States.door; }
        else if (Input.GetKeyDown(KeyCode.P)) {myState = States.pillow; }
        else if (Input.GetKeyDown(KeyCode.W)) {myState = States.wardrobe; }
        }

Sorry I think I just figured it out. Unity uses the namespace using System.Collections by default. To use enum you need to haveusing System; :smile:

Thank you for your reply…

I changed using System.Collections

to

using System;

And nothing happens when I press play still :frowning:

update has to be upper case. Make it Update and it should work.

1 Like

good catch!!!

Just done that and it fixed the issue! You guys are awesome!

1 Like