- Home /
Why GUI doesn't appear?
Hi. First of all, I'm new with Unity.
I have a problem with GUI, sometimes appears but, in other projects, doesn't.
I used a code in a Tutorial for draw a Crosshair in the middle of screen, the code is:
var position : Rect;
var crosshairTexture : Texture2D;
function Start() {
position = Rect((Screen.width - crosshairTexture.width)/2, (Screen.height - crosshairTexture.height)/2, crosshairTexture.width, crosshairTexture.height);
}
function onGUI() {
GUI.DrawTexture(position, crosshairTexture);
}
I was doing other projects myself but, before I make my first game with Unity I wanted read some Tutorials and documentation. I was doing the FPS tutorial and when a I write the code the GUI Crosshair doesn't appears in screen. I attachs that script on a Empty GameObject called GUI.
I'm doing something bad? (GUI.Label doesn't appears too)
Answer by Default117 · Nov 22, 2011 at 05:44 AM
First ensure that you are actually assigning a texture to crosshairTexture
, make it a public variable so that it will be exposed in the inspector and drag a texture onto it.
Thanks, but I think in JS all variables are publics except you write private before. I found the answer, my problem are the spaces. After a "(" I have to press spacebar. I write again the code with spaces after all sentences and works fine. Problem Result.
How can I mark this like solved?
EDIT: Think I found it.
Really? Didn't think that that would have been the issue! Oh well, glad it works now! As for the automatic public variables, i wasn't sure if it was C# or JS which makes them public automatically, so i just provided that anyway =P
It's not about spaces after parentheses. The reason nothing was getting drawn before probably had more to do with OnGUI being with a capital O. ;) $$anonymous$$onoBehavior doesn't have a function called onGUI, as you can see:
http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.OnGUI.html
$$anonymous$$aybe you ended up correcting that at the same time as the parenthesis+space-thing, and it looked like the space had fixed it?
Your answer
Follow this Question
Related Questions
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Move GUI elements. 0 Answers
GUITexture Button? 1 Answer
GUI Transparency Changing automatically 2 Answers
Write a Shader for GUI (GUITexture or scripted GUI) 0 Answers