How I can use the new GUI with c#?

Hi,

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

Thanks!

Something like this:

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour
{
	void OnGUI ()
	{
		if (GUI.Button ( new Rect (5, 5, 100, 50), "Button") )
		{
		}
	}
}

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?

:shock: Thanks!

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

Thanks! Daniel and Shaun.

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

:smile: