Controlling with touch

Now that we have several objects flying around in our space scene, including some that will shoot at the player, we should give the player the ability to do more than just dodge. One of the most obvious features of the modern mobile device is the touch screen. The devices use the electrical conductivity of the user's finger and many tiny contact points to determine the location that is being touched. Unity provides us with easy access to the touch inputs. By combining the input with ray casts, as we did for making the tanks fire, we can determine which object in the 3D space was touched by the user. For us, this means we can give the player the ability to shoot at and destroy the objects in space.

Get Unity Android Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.