- Home /
Unity GUI Layout and buttons wont show up
So I am starting to build a unity gui menu and buttons are not showing up. Here is my entire script for it:
function OnGui() {
//GUILayout.BeginArea (Rect (meshPosition.x, meshPosition.y, 300, 300));
GUILayout.BeginArea (Rect (0, 0, 300, 300));
GUILayout.BeginHorizontal();
if(GUILayout.Button("button1", GUILayout.height(100))) {
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
Am I missing something more than just the OnGui() function?
appreciate the help
Answer by Jamora · Aug 02, 2013 at 06:38 AM
The name of the function is OnGUI() . Capitalization matters. Otherwise your code looks like it'll compile and work.
Thanks a lot for the response, I thought that might be the case, so i tried it but still no GUI. I currently have the script attatched to a primitive game object with mesh renderer. Not sure if this is an issue.
Did you attach it to a prefab or a gameobject in the scene?
After having copied the code, I seem to have missed your GUILayout.Height typo; it is also capitalized.
In case you're using C#, you need to also add the new keyword before Rect i.e. new Rect()
its attatched to a gameObject, not a prefab. The language is UnityScript. When I get to my computer I will check the .Height typo and hopefully that will do the trick.
Answer by boni · Aug 02, 2013 at 07:33 PM
Additionally to the capitalization problem, could it be that you forgot to attach a GUILayer Component to your camera? :)
It is there by default. So except if he removes it, it should be there.
Your answer
Follow this Question
Related Questions
GUI elements not showing in Android and Web player 1 Answer
GUI Rect not showing on play 2 Answers
What is a good component to use for a GUI inventory display? 1 Answer
GUI.Label is not showing up! 1 Answer
problem with gui 2 Answers