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 OnMouseXXX 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 OnMouseXXX events bad for the performance in on handheld devices?
They are not bad for performance. I haven't experienced any bad performance with them but the reason you are getting that error is because it is likely that Unity is doing more work on mobile in order to get it working. It's not made for that but you should't notice any performance hit just by using them.
The
OnMouseDrag
andOnMouseDown
functions were specifically made for desktops. Yes, they work on mobile devices too but should be avoided.They should be avoided because they don't work for all Objects. For example, they don't work on the new UGUI system.
You should be using
OnBeginDrag
andOnEndDrag
which both requires you implementIBeginDragHandler
andIEndDragHandler
.The
OnBeginDrag
andOnEndDrag
functions will work on all GameObjects including 3D, 2D and the UI. For 2D you need to attachPhysics2DRaycaster
to the camera. For 3D, you have to attachPhysicsRaycaster
to the camera.See this post for how to get it work on any GameObject.