Search Unity

Menu not working

Discussion in 'Animation' started by karina_mady, Apr 16, 2014.

  1. karina_mady

    karina_mady

    Joined:
    Mar 16, 2014
    Posts:
    18
    Hi,

    I've been trying to create a simple menu with 2 entries. Both of the entries are supposed to open the same scene, the only different thing is that a boolean is set depending on which entry is pressed.

    Here is a screenshot of the menu:
    $menu.png

    Here is the script for it:
    $menuScript.png

    This is some additional code that just makes is clearer why I need

    if ( MenuScript.automate == true)
    runAutomatically ();
    else if (MenuScript.automate == false)
    runOnKeyInput ();


    I need to mention that I have added the MenuScript to my empty MenuController game object and I have added box colliders for the 2 entries in the menu.


    Thanks,
    Karina
     
  2. karina_mady

    karina_mady

    Joined:
    Mar 16, 2014
    Posts:
    18
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,702
    Are you sure that the Raycast is hitting the buttons? Try adding Debug.Log() statements. Or consider using OnGUI() instead of GUIText. You could replace Update() with:
    Code (csharp):
    1.  
    2. void OnGUI() {
    3.     GUILayout.Label("Run Animation");
    4.     if (GUILayout.Button("Automatically")) {
    5.         GotoNextLevel(true);
    6.     }
    7.     if (GUILayout.Button("On Key Press")) {
    8.         GotoNextLevel(false);
    9.     }
    10. }
    11.  
    12. private void GotoNextLevel(bool autoValue) {
    13.     automate = autoValue;
    14.     Application.LoadLevel("Robot");
    15. }
    16.  
    If you don't like the appearance of the GUI labels and buttons, you can create a custom GUI skin and assign it to GUI.skin at the beginning of OnGUI:

    Code (csharp):
    1.  
    2. public GUISkin customSkin; // <-- Assign this in the inspector.
    3.  
    4. void OnGUI() {
    5.     GUI.skin = customSkin;
    6.     GUILayout.Label("Run Animation");
    7.     if (GUILayout.Button("Automatically")) {
    8.         GotoNextLevel(true);
    9.     }
    10.     if (GUILayout.Button("On Key Press")) {
    11.         GotoNextLevel(false);
    12.     }
    13. }
    14. ...
    15.  
     
  4. karina_mady

    karina_mady

    Joined:
    Mar 16, 2014
    Posts:
    18
    Thank you very much, this is much cleaner and easier to use. :)