Search Unity

Multiple buttons on gui

Discussion in 'Scripting' started by Mirace, Feb 2, 2013.

  1. Mirace

    Mirace

    Joined:
    Nov 29, 2010
    Posts:
    481
    Hello,

    I want to draw 5 buttons to screen. How to do this?
     
  2. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Code (csharp):
    1.  
    2. function OnGUI(){
    3.        if( GUILayout.Button("hello") )
    4.           //Stuff
    5.        if( GUILayout.Button("hello") )
    6.           //Stuff
    7.        if( GUILayout.Button("hello") )
    8.           //Stuff
    9.        if( GUILayout.Button("hello") )
    10.           //Stuff
    11.        if( GUILayout.Button("hello") )
    12.           //Stuff
    13. }
     
  3. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
  4. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,250
    or you can just use the GUIButton 5 times.

    Code (csharp):
    1.  
    2.     if (GUI.Button(Rect(10,10,50,50),btnTexture))        Debug.Log("Clicked the button with an image");    if (GUI.Button(Rect(10,70,50,30),"Click"))        Debug.Log("Clicked the button with text");
    3.  
     
  5. Mirace

    Mirace

    Joined:
    Nov 29, 2010
    Posts:
    481
    :) Ofcourse i forgot to add on my first post.. so they need to be array. And Javascript.
     
  6. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,250
    In an array how?

    Why do you need them in an array?

    If it is just like push button 1 arr[0] = false, etc just put the part of the array in the if argument.
     
  7. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
  8. Mirace

    Mirace

    Joined:
    Nov 29, 2010
    Posts:
    481
    Because im bad with C# :)