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)
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!");
}
}