Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[HELP] Script not executing

Discussion in 'Editor & General Support' started by Knighty, Oct 7, 2015.

  1. Knighty

    Knighty

    Joined:
    Oct 2, 2015
    Posts:
    5
    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..

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class TextController : MonoBehaviour {
    6.    
    7.     public Text text;
    8.     private enum States {
    9.         room, door, pillow, wardrobe, door1, completed
    10.     };
    11.     private States myState;
    12.    
    13.     // Use this for initialization
    14.     void Start () {
    15.         myState = States.room;
    16.     }
    17.    
    18.  
    Please help :(

    new text section.PNG
     
  2. Knighty

    Knighty

    Joined:
    Oct 2, 2015
    Posts:
    5
    Hi, yeah of course! -

    Code (CSharp):
    1. private States myState;
    2.    
    3.     // Use this for initialization
    4.     void Start () {
    5.         myState = States.room;
    6.     }
    7.    
    8.     void update () {
    9.         print (myState);
    10.         if         (myState == States.room)        {state_room ();}
    11.         else if (myState == States.door)         {state_door ();}
    12.         else if (myState == States.pillow)         {state_pillow ();}
    13.         else if (myState == States.wardrobe)    {state_wardrobe ();}
    14.         else if (myState == States.door1)        {state_door1 ();}
    15.         }
    16.        
    17.     // Update is called once per frame
    18.     void state_room () {
    19.         text.text = "You wake up after hearing a loud bang, what could it be?!" +
    20.                 "You look around and you can see the door is closed, the blinds " +
    21.                 "are shut and your girlfriend is no longer sleeping next to you.\n\n" +
    22.                 "Press 'D' to open the door, Press 'P' to look under your pillow and "+
    23.                 "'W' to check the wardrobe.";
    24.         if (Input.GetKeyDown(KeyCode.D)) {myState = States.door; }
    25.         else if (Input.GetKeyDown(KeyCode.P)) {myState = States.pillow; }
    26.         else if (Input.GetKeyDown(KeyCode.W)) {myState = States.wardrobe; }
    27.         }
     
  3. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
    Sorry I think I just figured it out. Unity uses the namespace
    Code (CSharp):
    1. using System.Collections
    by default. To use enum you need to have
    Code (CSharp):
    1. using System;
    :D
     
  4. Knighty

    Knighty

    Joined:
    Oct 2, 2015
    Posts:
    5
    Thank you for your reply..

    I changed
    Code (CSharp):
    1. using System.Collections
    to
    Code (CSharp):
    1. using System;
    And nothing happens when I press play still :(
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    update has to be upper case. Make it Update and it should work.
     
    holliebuckets likes this.
  6. holliebuckets

    holliebuckets

    Moderator

    Joined:
    Oct 23, 2014
    Posts:
    496
    good catch!!!
     
  7. Knighty

    Knighty

    Joined:
    Oct 2, 2015
    Posts:
    5
    Just done that and it fixed the issue! You guys are awesome!
     
    holliebuckets likes this.