Making a GUI button

Can anyone help me out with coding a GUI button that you’d put in the game? I’m not new to code but i’m at a noob level, thanks!

Where’s the code? Have you even tried or read the docs?

Seriously, people should start researching not expect everyone else to do it for them.

I don’t expect someone to do it for me, I am just asking for help i’m not greedy :stuck_out_tongue:

Was not aimed directly at you, sorry.

It’s alright thanks for you help though and yes I hate people who’re very demanding, I get help from people so I like to give back by helping also one more question I used the button you have changed the text inside is there anyway of changing the position on the x,y, and z axis? Tried going with a empy game object didn’t work out.

GUI doesn’t care about the GameObject it is on. Also GUI is rendered on top of everything else.

Look at Unity - Scripting API: Rect
in particular: http://docs.unity3d.com/Documentation/ScriptReference/Rect.Rect.html

and modify the Rect in here

 if (GUI.Button (Rect (10,10,150,100), "I am a button")) {

Good luck :slight_smile:

Thanks! :smile:

Also anyway to make it so when you click it plays an audio clip

var audioClip : AudioClip;

function OnGUI () {
	if (GUI.Button (Rect (10,10,100,100), "Start Game")) {
		print ("You clicked the button!");
	}
}

function OnMouseDown(){

	audio.PlayOneShot(audioClip);
	
}

is what I was thinking didn’t work though.

…

move the playoneshot to where you print out “you clicked the button”, get rid of onmousedown

Thank you guys!