Game Development Reference
In-Depth Information
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 prop-
erly assign. We will do that in the
Start
function. We will also add the
Update
func-
tion 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 filled with a
few stats that we created.