x


how to make a button work on main menu?

well i was going through unity forums and saw the button script. i made a decent looking and working main menu... exept for the button doesnt work. so i thought the button script might work with my level changing script.

// JavaScript

function OnGUI () { // Make a background box GUI.Box (Rect (10,10,100,90), "Loader Menu");

 // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
 if (GUI.Button (Rect (20,40,80,20), "Level 1")) {
     Application.LoadLevel (1);
 }

 // Make the second button.
 if (GUI.Button (Rect (20,70,80,20), "Level 2")) {
     Application.LoadLevel (2);
 }

}

so i copied it and then i thought id try to change it up to where it would work with it. but i cant even get anything to show up when i use it, theres no compiler errors, but it doesnt work. why?

// JavaScript

function OnGUI () { if (GUI.Button (Rect (10,10,150,100), "I am a button")) { print ("You clicked the button!"); } }

more ▼

asked Mar 17, 2012 at 05:41 PM

felix420 gravatar image

felix420
0 9 6 7

@felix420,

Your post (as it appears now) probably isn't appropriate for UnityAnswers. The UnityAnswers philosophy is:

"[Unity Answers] is a place to ask specific questions that have specific answers. The forum is a better place to post discussions and non-technical questions."

As a general rule, posts should probably have the following:

A clear question (what, specifically, are you trying to do?) Relevant background information (what have you already tried? what other things might be important for us to know?) Context information (what do you expect to happen? What is happening instead?) Your request (what specifically do you expect of the UnityAnswers community? Are you looking for links to relevant information, a chunk of code that you can use, ...?)

If your post is one of the following, you should consider changing it or asking on the forums instead:

A one- or couple-sentence post, especially with a broad question ("how do I make a game like Halo?") or no discernible question ("WebPlayer doesn't allow me to save to disk"). We'll need more specific information to help you. Asking the opinion of the community ("Best method to store files?"). Much better to discuss these on the forums. A question that focuses on the end result, rather than anything technical ("how do I make a laser beam?"). These mean that you probably haven't done enough research. If you're just starting out and don't even know where to look, try searching here, the forums, and Google first and then posting your question to the forums. The Unity resources are a great place to start (http://unity3d.com/support/resources/). When you get to a more technical point ("how do I adjust the color of a line renderer for a laser beam?") we can probably help you. A disjointed or incomplete question ("How do I make a jumping enemy? Physics doesn't look right."). It will help us if you take a moment to add some context information, background, and general explanation. * Copying your code verbatim with a one-line question like "why doesn't this work?" or "what is wrong with my code?" To the community, this sounds like you came across an error, spent 0 time trying to fix it yourself, and simply posted it in the hope that someone else would do your work for you.

Finally, make sure that you check to make sure your question hasn't already been answered here, and do a quick google search, before posting a new question.

Of course, the members here are awesome folks and will probably try to help you anyway - hopefully you'll get an answer or some helpful comments. If not, now you know why.

Mar 17, 2012 at 05:56 PM Julien.Lynge

Yes, we need more detail, what is not working? Any errors?

Mar 17, 2012 at 09:08 PM CC Inc

Your problem is probably the z depth of your buttons on the GUI ... Is your GUI.Box being rendered, but no buttons? If so, try GUI.depth, and reorder your drawn elements so that . Alternatively, it could be a problem with positioning (your buttons may be being drawn off the screen, in which case you would use Screen.width and Screen.height to account for different screen sizes).

Without more information, there's no way we can know for sure.

Mar 18, 2012 at 01:22 AM Kleptomaniac

you might of forgotten to attach the script to something within your scene.

Mar 18, 2012 at 05:05 AM Eli Davis
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1416
x624
x504
x60
x59

asked: Mar 17, 2012 at 05:41 PM

Seen: 1114 times

Last Updated: Mar 18, 2012 at 06:33 AM