- Home /
What shall I use instead of OnMouse_ event handlers?
I've build a little app where I use OnMouseDrag and OnMouseDown in some objects. I thought that it would be the best option because this methods were out of the Update method. However at compiling the app Unity says "Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices."
So... what should I use instead of OnMouseDrag and OnMouseDown?
I've seen that i could use Input.GetMouseButtonDown. But to do this I will have to add an Update method to every object that has the OnMouseDown. Isn't it worst than having the OnMouseDrag?
And, why are OnMouse events bad for the performance in on handheld devices?
Answer by Brogan89 · Jun 16, 2017 at 08:00 AM
if you are using mobile and you are talking about UI then using UnityEngine.EventSystems is paramount. There are many interfaces you can implement.
I'm not talking about UI, i'm talking about objects that you move draging it with the finger.
Oh right. I would use Raycasting then. Unify has a good example http://wiki.unity3d.com/index.php/OnTouch hopefully that helps. As far as i know there is no out of the box function for this
But adding an Update method to every single object that has an On$$anonymous$$ouse_ is worth it?
If it gets the job done, then yes it is worth it. Depending on how many objects you are taking I will be fine. Unity can handle a lot, its a game engine, its what is it build for. Just keep trashing the update until it becomes a problem. Otherwise you could do it within a coroutine, but its more or less the same thing.
Your answer
Follow this Question
Related Questions
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Creating object and collections at runtime 1 Answer
Multiple Cars not working 1 Answer
Choppy Character Movement Unity 2D 0 Answers
Distribute terrain in zones 3 Answers