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

Please Help - Menu showing in PLAY but not in EXE format

Discussion in 'Scripting' started by GamezGlitchZ, Jun 29, 2014.

  1. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    Basically when i click Play...the menu shows when i click ESCAPE but when i compile it into EXE
    Code (csharp):
    1.  
    2. @script ExecuteInEditMode()
    3.  
    4. var menucounter = 1;
    5. var menu = true;
    6. var options = false;
    7. var sound = false;
    8. var video = false;
    9.  
    10. var sfxVol : float = 0.6;
    11. var musicVol : float = 0.6;
    12.  
    13. var fieldOfView : int = 80;
    14.  
    15. var mainCam : Camera;
    16. var mainSkin : GUISkin;
    17.  
    18. function OnGUI () {
    19.    GUI.skin = mainSkin;
    20.  
    21.    if(Input.GetKeyDown(KeyCode.Escape)){
    22.      menucounter++;
    23.      options = false;
    24.      sound = false;
    25.      video = false;
    26.      print(menucounter);
    27.    }
    28.  
    29.    if(!options && !sound && !video)
    30.      menu = !(menucounter/2 % 2 == 0);
    31.  
    32.    if(menu) {
    33.      GUI.Box(Rect(Screen.width/2-75,Screen.height/2-65,200,250), "Game Menu");
    34.      if(GUI.Button(Rect(Screen.width/2-50,Screen.height/2+10,150,30), "Single-Player")){
    35.        Application.LoadLevel("SavageGame0.008a");
    36.      //play game
    37.      }
    38.      if(GUI.Button(Rect(Screen.width/2-50,Screen.height/2+50,150,30), "Multi-Player")){
    39.      }
    40.        if(GUI.Button(Rect(Screen.width/2-50,Screen.height/2+90,150,30), "Game  Options")){
    41.          menu = false;
    42.          options = true;
    43.      }
    44.      if(GUI.Button(Rect(Screen.width/2-50,Screen.height/2+130,150,30), "Main  Menu")){
    45.        Application.LoadLevel("SavageIntroSceneFLAlpha0.008a");
    46.      
    47.      }
    48.    
    49.    
    50.      if(GUI.Button(Rect(Screen.width/2-50,Screen.height/2+170,150,30), "EXIT  GAME")){
    51.        Application.Quit();
    52.      }
    53.    
    54.  

    this is a part of the code, the problem i have is with the ESCAPE key, its not showing in EXE format(BUILD & RUN)
    THANK YOU AHEAD OF TIME[/CODE]
     
    Last edited: Jun 29, 2014
  2. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
  3. Turbo420

    Turbo420

    Joined:
    Jun 24, 2014
    Posts:
    61
    try removing line 26.just a guess tho.
     
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Missing a }
    (maybe just a copy error)
     
    Turbo420 likes this.
  5. Turbo420

    Turbo420

    Joined:
    Jun 24, 2014
    Posts:
    61
    where is all this at? and what is this about @script ExecuteInEditMode(); ???


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class namehere : MonoBehaviour {
     
  6. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
  7. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    tried removi
    tried that...no luck...in game it works perfectly...in build and run it dosnt...
     
  8. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    i tried several things but i cant freaking figure it out...HOW THE HELL IS IT WORKING in PLAY MODE but NOT IN BUILD! how is that POSSIBLE! i never had anything work in PLAY and not work in BUILD AND RUN!....ERRR i spend over 3 hours trying to figure this thing out...
     
  9. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    copy error, i just copied part of the code, all i want escape to do is show menu lol !_!
     
  10. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    any ideas guys =(
     
  11. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    put #pragma strict
    all the way at the top of your code.
    Then check if you have errors.
    Copy & Paste those errors in here!

    Javascript really should show errors by default. -_-
     
  12. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    Also, there should be a log file at the root of the compiled version.

    There you can see what are the errors happening silently and preventing your script from executing correctly.
     
  13. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    Unfortunately it seems no-one really bothered to read your code.

    As previously stated by yourself in fact, you are using @script ExecuteInEditMode(), which means your code will only work in the editor, not when using build & run.

    Remove the first line and your code will run in editor and the built program.

    A few more points though:

    Firstly, you have a very odd way of opening a menu, I'd reconsider this before actually trying to fix this issue. There are simpler methods...

    So you initially set menucounter to 1.
    Then you check for the escape key down in OnGUI (very bad idea, this should be in Update, OnGUI can be called more than once per frame). If correct you add to menucounter.

    Then you are setting a bool that will be false when your menucounter is a multiple of 4... I am not sure why this is, I assume you have your reasons...

    I'd advise re-examining your code structure for this feature, and taking a look at the documentation for a better understanding of how to design your code.

    http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnGUI.html
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html
     
    Last edited: Jun 30, 2014
  14. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
     
    Magiichan likes this.
  15. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Don't make false claims.
    The OP described it to work while he's in unity. So the logical thing to think would be that it does run the code while at runtime.

    edit:
    And what @_met44 said
     
    Last edited: Jun 30, 2014
  16. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    633
    OP, did you have a look to the log file ? The error should be near the end.

    Also, as stated before I must advise you to change your input method. The input class is meant for use in the Update() :

    If you want to handle everything from the OnGUI() you can do this:
    Code (csharp):
    1. if (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.Escape) {}
     
    Last edited: Jun 30, 2014
  17. 3agle

    3agle

    Joined:
    Jul 9, 2012
    Posts:
    508
    Ah, my apologies, I'm confusing ExecuteInEditMode with platform specific compilation.

    The code restructuring outlined in my first post should still help, as polling inputs in OnGUI is a bad idea.
    It's likely that menucounter is being set elsewhere in code, too. (posting the rest of the code would be useful)
     
  18. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    tried what u recommended..sorry to say it didnt work... =(
    for removing the line...executeineditmode
     
  19. GamezGlitchZ

    GamezGlitchZ

    Joined:
    Jun 15, 2014
    Posts:
    26
    Now all i need is to put another statement in there if its already true make it false...anyone got any good recommendations?