Important Notes on Touch Input in Unity

There are a few things that you will want to keep in mind when working with touch in Unity. Mobile devices pass click events with their touch events, platform dependent compilation, rotations are a special type all their own, sometimes Unity hands back one thing when you need another, collisions are odd, and much more. This is the first of many posts on the quirks of Unity.

If you are planning to support multiple platforms, I highly recommend taking advantage of platform dependent compilation. This will help to avoid several conflicts, and will cut back on stacked code considerably.

The reason for the push is that all tested mobile devices will pass a click event alongside a touch event. What does this mean? Well, it means that if you have just single click input, you don't actually have to code in a touch handler. This is by design as it allows for web browsing capability, among other things. Just keep in mind that having a state machine can help with interference in pretty much every case (more on state machines later). Having platform dependent compilation can eliminate the interference entirely, provided the code is nicely separated.

A future post will provide the basic methods for handling touch input by the user and making it able to share a handling function with the mouse.

Show Comments