I am making a main menu. What i want to happen is, when you hover over the “Play Game” or the “Quit” button it will turn green, and then when you hover off it will turn white. I also want it to load the level, in my build settings i have the main menu screen as “0” and my first level at “1” . What did i do wrong?
var isQuitButton = false;
function OnMouseEnter()
{
//Change the color of the text
renderer.material.color = Color.green;
}
function OnMouseExit()
{
//Change the color of the text
renderer.material.color = Color.white;
}
function OnMouseUp()
{
//are we dealing with a Quit Button?
if( isQuitButton )
{
//quit the game
Application.Quit();
}
else
{
//load level
Application.LoadLevel(1);
}
}
You explained what you want it to do, you didn’t describe what it does, how the script is attached, for all we know this partial script is attacked to an empty gameobject doing nothing.
What does it do: Currently its does not do anything,as i said i want it to load the level when you click “Play Game” and change to the color green when you hover over it. Thats why i used the code
function OnMouseEnter()
{
//Change the color of the text
renderer.material.color = Color.green;
I have a box collider on the text and it is a trigger, with this code attached. On the “Quit” 3d text, i have a box collider and i have it a trigger. It also has the same code as the “Play game”
When i play the game, it does not change a different color, nor does it play/quit the game when i click on the 3d text.
If anyone could help, that would be great thanks:)
Mycroft provided the links for you to learn. GUISkin will give you the ability to change the presentation of the UI and GUI link will describe setting up in this case a single button(which again with the skin you can make look any way you want).
Unless there is a reason(performance and such) your probably wasting your time reinventing the wheel.
With that said, you shouldn’t be having any or much difficultly with OnMouseEnter as long as your script is attached to the game object and the game object actually has a collider. If it doesn’t have a collider then OnMouseEnter doesn’t raise when you put your mouse over the collider.
Otherwise, please provide more detail/screen shots.