Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

How I can use the new GUI with c#?

Discussion in 'Immediate Mode GUI (IMGUI)' started by RJofre, Nov 12, 2007.

  1. RJofre

    RJofre

    Joined:
    Nov 12, 2007
    Posts:
    4
    Hi,

    can somebody tell me how I can use the new GUI with c#?
    :eek:

    Thanks!
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Something like this:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour
    5. {
    6.     void OnGUI ()
    7.     {
    8.         if (GUI.Button ( new Rect (5, 5, 100, 50), "Button") )
    9.         {
    10.         }
    11.     }
    12. }
    13.  
     
  3. RJofre

    RJofre

    Joined:
    Nov 12, 2007
    Posts:
    4
    Thanks Daniel!

    What you have told me works right, I can see the button when I run the game, but it appears the follow message in the console (error in line 26):



    Assets/Script/test.cs(26) error: Expression denotes a `type', where a `variable', `value' or `method group' was expected


    (I put the line numbers like a guide)

    ...
    26 void OnGUI ()
    27 {
    28 if (GUI.Button ( new Rect (5, 5, 100, 50), "Button") )
    29 {
    30 print ("You clicked the button!");
    31 }
    32 }
    ...

    Do you know what happend?

    :eek: Thanks!
     
  4. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    RJofre - your error is coming from test.cs - the Script from Daniel is fine, but it has to be called NewBehaviourScript.cs.

    In Unity, the filename must match the Class name.

    Cheers
    Shaun
     
  5. RJofre

    RJofre

    Joined:
    Nov 12, 2007
    Posts:
    4
    Thanks! Daniel and Shaun.

    I made a new file with the code and it works perfectly!

    :D