- Home /
i want to rotate an object when i move my mouse over an UI image
I has a cube in my scene and i added a UI canvas which has a image in it. I just simply want to rotate my cube object when my mouse moves over the image and stop the rotation when my mouse moves out of the image? Previously in older version of unity i was able able to do this by mouse enter and exit function but i have no idea with the new UI of new version. Please help
Answer by fffMalzbier · Oct 26, 2015 at 05:16 PM
The easiest way is to use the Event Trigger Component. The component can call functions / change variables based on ui events. The events you should take a look at are PointerEnter and Pointer exit. http://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html There is a way to get the vents directly in your script but its not so easy that i would recommend it for the beginning.
http://docs.unity3d.com/ScriptReference/EventSystems.IPointerEnterHandler.html http://docs.unity3d.com/ScriptReference/EventSystems.IPointerExitHandler.html for the example how the unity button uses the interfaces to functin you can take a look here https://bitbucket.org/Unity-Technologies/ui/src/a5f41955ad119e1708b79f10154009c984992769/UnityEngine.UI/UI/Core/Button.cs?at=5.2&fileviewer=file-view-default
Your answer
Follow this Question
Related Questions
Authoritative Rotation 2 Answers
Rotation of Object on single axis in direction of the mouse position 0 Answers
Slerp/Rotational Problem Query 1 Answer
Object Look At Mouse 2 Answers
Re-center UI Image after zooming out 0 Answers