If Mouse cursor is above an object, start animation (without click on It)
Hi, I have 5 planes, which are buttons of the menu, how can I do to start a simple button's animation when the mouse cursor is on the button? (without click on it!) Thank you :)
Answer by Dinosaurs · Oct 22, 2015 at 08:53 PM
If you're using the Unity UI system, you can hook onto the IPointerEnterHandler event handler.
If not, you can try using Rect.Contains(Vector3) to check if the mouse is over the button. To do that you'll need to convert the corners of your plane into a rect, probably using Camera.WorldToScreenPosition. http://docs.unity3d.com/ScriptReference/Rect.Contains.html
Or, if the buttons have colliders, you could cast a ray from the mouse position into the scene to check if the cursor is over the collider. http://docs.unity3d.com/ScriptReference/Input-mousePosition.html
Or, if the buttons have colliders, you could cast a ray from the mouse position into the scene to check if the cursor is over the collider.
A suggestion would be to use a PhysicsRaycaster together with EventSystem ins$$anonymous$$d.
This will also ensure that rays are blocked by UI.
The solution was simple, function On$$anonymous$$ouseEnter() With this I solved my problem!
Answer by Statement · Oct 22, 2015 at 09:08 PM
Unity has a video showing how to add animations to buttons. Just make sure to have a trigger for the Highlighted Trigger and an actual animation created using the animation editor. It can be a one frame animation. Unity will smoothly blend between them.