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

C# GUI variables

Discussion in 'Scripting' started by herold101, Jul 1, 2014.

  1. herold101

    herold101

    Joined:
    Jan 20, 2014
    Posts:
    22
    Hello, I am wondering how I can assign a variable to a GUI component.

    Let me explain it using this example:

    Code (CSharp):
    1.         if (GUI.Button(new Rect(20, 40, 80, 20), "Start"))
    2.         {
    3.             Application.LoadLevel(1);  
    4.         }
    5.  
    6.         if (GUI.Button(new Rect(20, 70, 80, 20), "Settings"))
    7.         {
    8.            
    9.         }
    10.  
    11.         if (GUI.Button(new Rect(20, 100, 80, 20), "Dev Team"))
    12.         {
    13.            
    14.         }
    15.  
    16.         if (GUI.Button(new Rect(20, 130, 80, 20), "Quit"))
    17.         {
    18.            
    19.         }
    20.         if (Window1)
    21.         {
    22.             GUI.Box(new Rect(10, 200, 200, 200), "Settings");
    23.         }
    24.         if (Window2)
    25.         {
    26.             GUI.Box(new Rect(10, 200, 200, 200), "Dev Team");
    27.         }
    28.     }      
    29. }
    I have already assigned public bool Window1, etc.

    In my idea it would be easy to just assign a variable to the GUI button that says settings and the GUI button that says Dev team. Once those variables are set I can make the GUI box called settings apear and disapear upon the button press, However I do not know how to declare a variable for a specific GUI.

    If you know any 'easier' ways of doing what I wanted to do please tell me.

    ,Thank you.
     
  2. herold101

    herold101

    Joined:
    Jan 20, 2014
    Posts:
    22
    Anyone?
     
  3. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Whoa there, you shouldn't expect an answer in the first 20 minutes. A polite waiting time until you bump is 24-48 hours.
     
  4. herold101

    herold101

    Joined:
    Jan 20, 2014
    Posts:
    22
    Sorry :oops: , I just need to complete this for a private event and I only have 3 - 5 days left.
     
  5. herold101

    herold101

    Joined:
    Jan 20, 2014
    Posts:
    22
    Don't quite know how to mark a post solved. But I figured it out.
     
  6. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    You can:

    - Use delegate type function, to paint different Windows.
    - Divide GUI script in GameObjects. And after, activate/desactivate GameObjects to show/hide Window.