OnGui not working (again)

Hi, me again, I can’t make a Gui work, here’s my script, I’ve tried with both “OnGUI” and “OnGui” and I can’t get it work. Am I doing something wrong??!!

I started a new project, and attached my c# script to my camera, it didn’t work, I tried with empty objects and nothing, I also tried with Button, Text , and also Nothing!!

public class Example : MonoBehaviour {

	void OnGui () 
	{
		GUI.Label (new Rect (10, 10, 100, 20), "Hello World!");
	}
}

public class Example : MonoBehaviour {

	void OnGUI () 
	{
		GUI.Label (new Rect (10, 10, 100, 20), "Hello World!");
	}
}

First off, the right syntax is the second one : OnGUI

Other than that, everything seems ok… now, not to sound rude or anything, but here’s a few things that might prevent it from working :

  • Is your script file named “Example.cs” ?
  • Did you save the script ?
  • Did you hit play ?

I actually copied the code and ran, it works fine.

hi. is it too late?
i had same problem and figured out it’s because of lighting problem.
first off, check the window → lighting setting. then just the skybox set to None.
if you may see the gui, then solve just lighting problem.

Another reason that the OnGUI could appear to not be working is if you changed the Game’s Free Aspect Scale to a large enough value that the text is simply off the camera view. Yes, it can be that simple.

Would you try to tap the “2D” button in the Scene?
I’m the beginner of Unity coding but It seems it matters that it is 3d or 2d.

Same here, OnGUI works only in play mode for me. (But I use [ExecuteInEditMode])

Half solution: void OnRenderObject() always works, but it’s executed far too many times per second.