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 – controlling the turret

This script will allow the player to rotate their turret and aim the cannon.

  1. The last script we need to create for our tank is TurretControls. This script will allow players to rotate the turret left and right and tilt the cannon up and down. As with all of the others, create it in the Scripts folder.
  2. The first two variables we define will hold pointers to the turret and cannon pivots, the empty GameObjects that we created for our tank. The second set is the speed that our turret and cannon will rotate at. Finally we have some limit values. If we didn't limit how much our cannon could rotate, it would just spin around and around, passing through our tank. This isn't the most realistic behavior for a tank, ...

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