Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how to make a simple GUI with five buttons

Discussion in 'Immediate Mode GUI (IMGUI)' started by Ixquic, Apr 7, 2014.

  1. Ixquic

    Ixquic

    Joined:
    Apr 7, 2014
    Posts:
    8
    Hello all, is my first time in this forum and i want to know if there is a description about how to
    create a simple GUI with five buttons. Well, i hope you answer me as soon as possible!

    Thank you and ;)
     
  2. BraveVN

    BraveVN

    Joined:
    Jun 12, 2013
    Posts:
    21
  3. Ixquic

    Ixquic

    Joined:
    Apr 7, 2014
    Posts:
    8
    Yeap BraveVN, is similar like that one! Do you know where is an example for begging? Thank you and ;)
     
  4. BraveVN

    BraveVN

    Joined:
    Jun 12, 2013
    Posts:
    21
    sorry for reply too late, here is my code for the GUI above:

    Code (csharp):
    1. void OnGUI(){
    2.     if (mainMenu) {
    3.         GUI.BeginGroup (new Rect (Screen.width / 2 - 300, Screen.height / 2 - 120, 600, 300));
    4.             GUI.Box(new Rect (0,0,600,95), "");
    5.             if (GUI.Button(new Rect(20,20,560,55), "<size=40><color=#FFFF00>Start</color></size>")){
    6.                 levelMenu = true;
    7.                 mainMenu = false;
    8.                 // do your stuffs
    9.             }
    10.            
    11.             GUI.BeginGroup(new Rect(0, 105, 295, 195));
    12.                 GUI.Box(new Rect(0,0,295,195), "");
    13.                 if (GUI.Button(new Rect(20,20,255,67.5f), "<size=30><color=#FFFF00>Option</color></size>")) {
    14.                     optionMenu = true;
    15.                     mainMenu = false;
    16.                     // do your stuffs
    17.                 }
    18.                 if (GUI.Button(new Rect(20,107.5f,255,67.5f), "<size=30><color=#FFFF00>Help</color></size>")){
    19.                     helpMenu = true;
    20.                     mainMenu = false;
    21.                     // do your stuffs
    22.                 }
    23.             GUI.EndGroup();
    24.            
    25.             GUI.BeginGroup(new Rect(305, 105, 295, 195));
    26.                 GUI.Box(new Rect(0,0,295,195), "");
    27.                 if (GUI.Button(new Rect(20,20,255,67.5f), "<size=30><color=#FFFF00>Facebook</color></size>"))
    28.                     // do some stuff
    29.                 if (GUI.Button(new Rect(20,107.5f,255,67.5f), "<size=30><color=#FFFF00>About</color></size>")){
    30.                     aboutMenu = true;
    31.                     mainMenu = false;
    32.                     // do your stuffs
    33.                 }
    34.             GUI.EndGroup();
    35.    
    36.         GUI.EndGroup();
    37. }
     
  5. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,355
    This is no good! It was a bad idea to show such a big code to a person who just learns programming. Let him do it by himself. Relying on others' work won't help you in the future.

    The best source is this one!

    Simply, take your time looking through it and you'll be able to make your own GUI without any help!
     
  6. BraveVN

    BraveVN

    Joined:
    Jun 12, 2013
    Posts:
    21
    haha, don't be angry, 1 month ago, I was stupid like him and I was so excited if anyone show me the fully code :D