Game Development Reference
In-Depth Information
public void UpdateAI()
{
if (enemyAI != null && EnemyProfile != null)
{
enemyAI.SetInteger("EnemyHealth", EnemyProfile.Health);
enemyAI.SetInteger("PlayerHealth",
GameState.currentPlayer.Health);
enemyAI.SetInteger("EnemiesInBattle",
battleManager.EnemyCount);
}
}
The preceding code just sets the properties of the AI to the current values. As the values
change, the AI will react based on the transitions that are defined. For example, if the
Goblin's health drops below 2 and the player's heath is greater than 2 , it will transition to
Run Away . Granted we are not doing anything with the states yet, but we will come on
to that later.
Next, we need to grab the reference to the AI that is currently configured against the game
object that will be used by the previous UpdateAI function in the Awake method:
void Awake()
{
enemyAI = GetComponent<Animator>();
if (enemyAI == null)
{
Debug.LogError("No AI System Found");
}
}
There are several logging options in Unity, from the basic Log to the more detailed Lo-
gWarning and LogError . These logging options provide us with more detail while de-
bugging our project, so use them wisely.
Tip
To save sanity when you are adding more content to the game, it is worthwhile to add
Debug comments, surrounding them with important components or scripts required by an
Search WWH ::




Custom Search