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 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