O'Reilly logo

Unity AI Game Programming - Second Edition by Thet Naing Swe, Clifford Peters, Aung Sithu Kyaw, Ray Barrera

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

Setting up the tank

The example project also includes a prefab for the tank, which is simply called (you guessed it) Tank, inside the Prefabs folder.

The tank itself is a simple agent with one goal—reach the end of the maze. As mentioned earlier, the player has to help the tank out along the way by activating its abilities to keep it safe from oncoming fire from the towers.

By now you should be fairly familiar with the components you'll encounter along the way, except for the Tank.cs component attached to the prefab. Let's take a look at the code to figure out what's going on behind the scenes:

using UnityEngine; using System.Collections; public class Tank : MonoBehaviour { [SerializeField] private Transform goal; private NavMeshAgent agent; [SerializeField] ...

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