Why are my android GUIs not showing and how can I fix it?

Hello, fellow unity users.

I started developing my first android game recently and I’ve already come across something strange &#9785. I’m creating a button controller for my character and here is my code:

function OnGUI() {
if(GUI.Button(Rect(10,10,50,50), "Up")) {
transform.position.y += 0.1;
}
}

The button isn’t showing whenever I run the game. Why not and how can I fix this?

That’s a pretty small Rect. My guess would be that the text doesn’t fit inside it, and therefore is being truncated, but it’s impossible to know without seeing your font settings etc. You have attached this script to an active gameobject in your scene hierarchy, right?

I’d suggest you try something more like:

 function OnGUI() {
 if(GUI.Button(Rect(10,10,300,200), "Up")) {
 transform.position.y += 0.1;
 }
 }