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

I need help with GUI C#

Discussion in 'Scripting' started by Atix07, Jul 29, 2013.

  1. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    Hello! Im new in scipting... so I need help :)
    I want to make a pause menu so I have to use GUI. I stoped the time but i cant make guı! or im making this wrong. Help please!

    [SUB]using UnityEngine;
    using System.Collections;

    public class genel : MonoBehaviour {

    void OnGUI () {
    if(ınput.getkeydown(getkey.escape)) {
    guı.box(new rect(10,10,100,200), "menu");
    }
    }
    [/SUB]
     

    Attached Files:

    Last edited: Jul 29, 2013
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    how i can make pause menu? when i pressed to escape button menu will come.

    its like:

    if(ınput.getkeydown(getkey.escape)) {
    guı.box(new rect(10,10,100,200), "menu");
    }

    its not working :) can someone help :)
     
    Last edited: Jul 29, 2013
  4. chummscrubber

    chummscrubber

    Joined:
    Jul 7, 2013
    Posts:
    6

    Ok so for starters the function is meant to be
    Code (csharp):
    1. GUI.Box(new rect(10, 10, 100, 200), "menu");
    note the capitals!.

    Also you should not use
    Code (csharp):
    1. if(input.getkeydown(getkey.escape))
    as this will fire repeatedly only when the Esc is being held down. Instead use a boolean value to flag it as being pressed once, then display, then if pressed again hide. Here is a example

    Code (csharp):
    1.  
    2. bool showMenu = false;
    3.  
    4. void OnGUI()
    5. {
    6.     if (showMenu)
    7.     {
    8.          GUI.Box(new Rect(10,10,100,200), "menu");
    9.     }
    10. }
    11.  
    12. void Update()
    13. {
    14.     if(Input.GetKeyUp(KeyCode.Escape)) {
    15.     {
    16.           showMenu = !showMenu;    // toggles the value between true/false
    17.     }
    18. }
    19.  
     
    Last edited: Jul 29, 2013
  5. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    thanks for help but its still not workinng? I atached it to the main camera of the first person comtroller.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class dememe : MonoBehaviour {
    6.    
    7.     bool showMenu = false;
    8.  
    9.     // Use this for initialization
    10.     void Start ()
    11.     {
    12.    
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.        
    18.         if (showMenu)
    19.         {
    20.             GUI.Box(new Rect(10,10,100,200), "menu");
    21.         }
    22.                    }
    23.         void OnGUI () {
    24.             if(Input.GetKeyUp(KeyCode.Escape)) {
    25.            
    26.                 showMenu = !showMenu;
    27.         }
    28.     }
    29. }
    30.  
     
    Last edited: Jul 29, 2013
  6. Atix07

    Atix07

    Joined:
    Jul 27, 2013
    Posts:
    182
    okayokay thanks alot! works perfectly! İ made an huge mistake! Okay im noob and learning scripting... sry! its working awesome! and u also teached me coding! thanks alot! #chummscrubber