I’ve gotten a GUI to work out, so I can help ^^.
First, your GUI scripts are all event-based (as you can probably tell from functionOnGUI() ). So, let’s start this from scratch.
1 - Let’s create a new JavaScript - call it “testGUI.js” or something. It should start off looking something like this:
function Start() {
}
2 - Now, we need to make one simple modification: change Start to OnGUI, so the script will look like this:
function OnGUI() {
}
3 - Now, we’re going to want something to be shown ON our GUI. We have a few basic possibilities in the Unity GUI API: Box, Label, Button.
Box and Label are similar. They code something like this:
GUI.Box( Rect( 10,10, 100,10 ), "Test GUI" );
GUI.Label( Rect( 10,10, 100,10 ), "Test GUI" );
These are functions that live in Unity’s GUI library. Box creates a box with “Test GUI” as it’s title caption. See the Rect() call in it? This is simply telling the Box to draw in a rectangle from (10,10), that is 100 pixels wide and 10 pixels deep.
So, we can make an easy GUI:
function OnGUI() {
GUI.Label( Rect( 10,10, 100,10 ), "Hello, world!" );
}
This code should make the phrase, “Hello, world!” appear in the top corner of the viewport when you run the game.

4 - To make things a bit more interactive, let’s add a quit button. (You have to build the application to see a quit button work, but here’s how you do it anyhow:)
We’re going to create a button. This is also a GUI call, but is slightly different from the Box and Label GUI objects:
if( GUI.Button( Rect( 10,10, 100,10 ), "This Game Sucks" ) ) { }
GUI.Button acts just like Label or Box - it has a rectangular region declared, and shows text, however input to Buttons are detected in if() blocks. Now, we wanted to make a quit button? We just need to add one line of text:
if( GUI.Button( Rect( 10,10, 100,10 ), "Quit" ) ) { Application.Quit(); }
5 - Let’s pull it all together!
function OnGUI() {
if( GUI.Button( Rect( 10,10, 100,10 ), "Quit" ) ) { Application.Quit(); }
}
Test run your game, or if you feel especially daring, build a development build and run it, then hit the quit button!