To wrap up our AI package, we will now finish up the script and add it to the skeleton.
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 Start
function, we first assign the navAgent
variable by getting the NavMeshAgent
component from the GameObject. Next, we add new KeyValuePair
variables to the Stats
array. The Stats
array is now...