O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

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

Putting it all together

To wrap up our AI package, we will now finish up the script and add it to the skeleton.

Final coding touches

At the beginning of our AI script, we created some variables that we have yet to properly assign. We will do that in the Start function. We will also add the Update function to run our AI code. Add these functions to the bottom of the class:

void Start()
{
  navAgent = GetComponent<NavMeshAgent>();

  Stats.Add(new KeyValuePair<string, int>("Health", 100));
  Stats.Add(new KeyValuePair<string, int>("Speed", 10));
  Stats.Add(new KeyValuePair<string, int>("Damage", 25));
  Stats.Add(new KeyValuePair<string, int>("Agility", 25));
  Stats.Add(new KeyValuePair<string, int>("Accuracy", 60));
}

void Update ()
{
  RunBehaviors();
}

In the ...

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