O'Reilly logo

Unity Android Game Development by Example Beginner's Guide by Thomas Finnegan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – touch to shoot

For making use of the touch inputs, we will need to add a single script to our player's ship:

  1. To give the player the ability to shoot, we need to first create a new script and call it TouchShoot.
  2. This script begins with a single variable. A LayerMask is used to selectively hit objects with a raycast. There are essentially a lot of layers that should be hit. This one will be used to determine what the player can or cannot shoot.
    public LayerMask touchMask = -1;
  3. The Update function is the only function in this script. It starts with a loop. The Input class provides us with the touchCount value, which is simply a counter for how many fingers are currently touching the device screen.
    public void Update() { for(int i=0;i<Input.touchCount;i++) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required