- Home /
Menu not working properly
I'm trying to make a main menu for my game here is the code I got for it -
var quitbutton = false;
function OnMouseEnter() {
renderer.material.color = Color.blue;
}
function OnMouseExit()
{
renderer.material.color = Color.white;
}
function OnMouseUp() {
if( quitbutton )
{
Application.Quit();
}
else
{
Application.LoadLevel(1);
}
}
but When I press the start button it wont load the next level (Yes there is another scene and it is marked as level 1 in the build settings), and when i build the game and run it when I hover over the text they dont change colors or anything, what did I do wrong? (I also checked the quitbutton in the start button's inspector menu)
According to this code, why would you expect the start button to load level id 1? All it says here, is that if you release the mouse - if the quitbutton is not pressed, level 1 will be loaded. Have you attached this script to a game object with a collider that is not ignored by ray cast (take a look at the layer - if its not marked as ignore raycast is should be ok).
Do you have a renderer component and a material attached to the game object on which this script is attached too?
@guyt it is not marked as raycast and yes the script is attached to both of the texts but no I do not have a renderer component nor a material attached to the object.
Answer by CHPedersen · Jun 28, 2011 at 06:28 AM
I formatted your code properly for you. In the future, please remember to use the button with the 0's and 1's on it. It formats code you paste, so it'll look nicer instead of getting line broken and mixed up with whatever else you write.
As for your problem, it seems to me you're approaching GUIs the wrong way. Have you taken a look at the GUI guide?
http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html
Buttons and menus etc. are far easier to make with the static functions in the GUI class. You call these functions in the OnGUI() function of a MonoBehavior. A button, for instance, can look like this (from the guide):
function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
print ("You clicked the button!");
}
}
I like the 3d text look a bit better It works fine when I'm in debug mod but it dosn't load the next level, and when I run the final build the 3d texts dont change color or react to the mouse entering it.
I see. Notice in the documentation about On$$anonymous$$ouseUp, that it says the function is only triggered when the mouse has been previously pressed down on the same GUIElement or Collider. This means that unless you have this script attached to the start button game object at the time you click and release the mouse while it's on the object, nothing happens.
The script is attached to the start button and the quit button. the quit button works fine in debug mode just not the start button and when i run the final build nothing works.
Your answer
Follow this Question
Related Questions
Why do I have to click GUI Menu twice to start in Web player? 0 Answers
How do I make a Quit To Menu script? 1 Answer
Making a Pause Menu 1 Answer
Using start function after loading level a second time 0 Answers
Lerpz Adventure Tutorial - Start Menu 2 Answers