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 – getting ready to fire

The enemy will shoot in a similar manner to how the player fires, but we will use some basic AI to control the direction and firing speed, replacing the player's input controls:

  1. We will start this off with a new script called ShootAtPlayer. Create it in the Scripts folder.
  2. As with all our other scripts, we start this one out with two variables. The first variable will hold the last position the enemy tank was at. It will not be shooting if the tank is in motion, so we need to store that last position to see if we have moved. The second variable will be the maximum speed at which we can move and shoot. If the tank moves faster than this, it will not fire.
    private Vector3 lastPosition = Vector3.zero; public float ...

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