x


Making a tray GameObject that slides out on mouse over

I'm making a scene where when you hover over the top corner, the tray slides into the scene, then slides out when you move the mouse off of the tray. I have that working smoothly with:

function OnMouseOver () 
{
    while (transform.position.x > 4.0)
    {
        transform.position =  transform.position - new Vector3 (0.1, 0, 0);
        yield WaitForSeconds (0.1);
    }
}

function OnMouseExit () 
{
    while (transform.position.x < 12.0)
    {
        transform.position =  transform.position + new Vector3 (0.1, 0, 0);
        yield WaitForSeconds(0.0001);
    }
}

However, I plan on adding other clickable objects on top of the tray, and when I hover over those objects, it counts as an "OnMouseExit" and closes the tray. What's the best way to avoid this but keep the objects clickable?

more ▼

asked Mar 13, 2011 at 02:43 AM

D168 gravatar image

D168
2 6 4 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You could have a short timer that must expire before closing the tray which is reset in OnMouseOver to work around this issue. Maybe you can fix it using Invoke and CancelInvoke?

more ▼

answered Mar 13, 2011 at 04:09 AM

Statement gravatar image

Statement
25.9k 76 108 240

(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x8745
x67
x54
x12

asked: Mar 13, 2011 at 02:43 AM

Seen: 1361 times

Last Updated: Mar 13, 2011 at 04:05 AM