i'm new to java programming and i wanna program a mouse over event. to be more specific
i want different cars to appear at mouse over event (to choose a car from five different cars)
and when you click the button i want it a go to a specific scene. so how do i program mouse over event and application.loalevel()in the same button
Answer by IgnoranceIsBliss
Jan 30, 2012 at 12:06 PM
Just as some hints to let you know where to look...
For 2D buttons, check out the 'GUI' classes in Unity. These will let you make text, buttons and other 2D objects that can be clicked and hovered over. You can use custom skin and backgrounds on your 'GUIStyle' class to try and draw different cars, if you like.
A little more tricky but more useful is doing it in 3D.
In this case, you put all of the cars in your scene and then - in a seperate layer - put an empty GameObject with a BoxCollider over each car.
Then you would make a Unity Behaviour that uses the Physics.Raycast and Camera.ScreenToWorldPos to fire a 'ray' (like a fake beam of light) into your scene from the mouse cursor to see what it might be hovering over. If it strikes one of those colliders, the mouse is over the car.
It's tricky - Unity is a 3D engine, not a 2D one. If you want a simple mouse-over on a 2D environment, I'd consider doing your game in HTML5 or Flash.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
6 People are following this question.
How to create GUITexture which does not react on over on transparent parts of it.
Layermask (raycast) wont work...
How to MouseOver Button on a Mesh?
Need Android Help - How do I click and mouseover a 3d object?
OnMouseOver is not working properly?