- Home /
Question by
93ys71me · May 19, 2013 at 03:33 AM ·
screenbuttonsmouseovermouse-over
Screen.width & Screen.height Becoming button
I found this code in the Unity document and I wanted to use it for my game here is the code:
/* Screen.width & Screen.height example */
var isQuitButton = false;
function OnMouseEnter()
{
//change the coler of the text
renderer.material.color = Color.green;
}
function OnMouseExit()
{
//change the coler of the text
renderer.material.color = Color.white;
}
// JavaScript
function OnGUI () {
GUI.Box (Rect (0,0,100,50), "Reset");
GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");
GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-left");
GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-right");
}
now what i want to do is to place an "OnMouseEnter() " function so that on line 15 the text can change color when the mouse overs and for the text "Reset" to be selectable as well,
This is the code that I'm using along with the first one but I'm getting all sorts of error
var isQuitButton = false;
function OnMouseEnter()
{
//change the coler of the text
renderer.material.color = Color.green;
}
function OnMouseExit()
{
//change the coler of the text
renderer.material.color = Color.white;
}
function OnMouseUp()
{
//is it a quit button?
if( isQuitButton )
{
//quit the game
Application.Quit();
}
else
{
//load level
Application.LoadLevel(1);
}
}
can somebody help me?
Comment
I did not spot any errors, so I pasted this code into a javascript file in Unity. Still no errors. What kinds of errors are you getting? Please post the exact code you have that generates the errors along with any error messages.
Have you looked into GUISkin? You could apply one of those and have mouseover effects with it.