Game Development Reference
In-Depth Information
Destroy(gameObject);
}
else if(Stats[i].Value < 25)
{
isSuspicious = false;
ChangeBehavior(Behaviors.Flee);
}
break;
}
}
}
This function takes an int variable, which is the amount by which we want to change
the health of the player. The first thing we do is check to see if the amount is neg-
ative; if it is, then we make our AI suspicious and change the behavior accordingly.
Next, we search for the health stat in our list and set its value to a new value that is
affected by the Amount variable. We then check if the AI's health is below zero to
kill it; if not, then we also check if its health is below 25. If the health is that low, we
make our AI flee from the player.
To finish off our actions, we have one last function to add. It will allow us to affect a
specific stat of the AI. These modifications will either add to or subtract from a stat.
The modifications can be permanent or restored anytime. For the following instance,
the modifications will be permanent:
void ModifyStat(string Stat, int Amount)
{
for(int i = 0; i < Stats.Capacity; i++)
{
if(Stats[i].Key == Stat)
{
int tempValue = Stats[i].Value;
Stats[i] = new KeyValuePair<string,
int>(Stats[i].Key, tempValue += Amount);
break;
}
}
Search WWH ::




Custom Search