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

GUI Problem. Editor works, build does not.

Discussion in 'Scripting' started by MarcAndreJolin, Jun 4, 2014.

  1. MarcAndreJolin

    MarcAndreJolin

    Joined:
    Apr 13, 2014
    Posts:
    2
    Hi, I have a problem that is reaaally annoying me.

    I have a really simple code that works perfectly fine when I launch it on the editor, but that goes nuts when I Build and Run it. I've been trying to find the problem for so long, but I can't seem to make it work. Here it goes :

    public class Menu : MonoBehaviour {

    bool inMenu = true;
    bool inLobby = false;

    void OnGUI(){
    if(inMenu){
    if(GUI.Button(new Rect(Screen.width-100, 0, 100, 50), "Connect")){
    inLobby = true;
    inMenu = false;​
    }​
    }else if (inLobby){
    GUI.Label(new Rect(Screen.width-100, 0, 100, 50), "Number of players: " + 1);
    if(GUI.Button(new Rect(Screen.width-100, 50, 100, 50), "Start Game")){
    Destroy(this);​
    }​
    }​
    }​
    }

    The Code in inMenu works fine, but as soon as I get inLobby in my Build, the inMenu code stays on. Here's a picture of the problem

     
  2. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    My guess is that you've somehow got two instances of the script running.
     
  3. MarcAndreJolin

    MarcAndreJolin

    Joined:
    Apr 13, 2014
    Posts:
    2
    That could have been it but to test the code, I created a new Project, put an empty GameObject and put my script in it.