Game Development Reference
In-Depth Information
Making the new GoblinEnemy game object a prefab and adding it to the
battle
Now that we have the new base for the Goblin, drag the GoblinEnemy game object to
Assets\Prefabs\Characters (delete the old one if you haven't already). When it's
created, delete the original GameObject from the Project hierarchy as we will only use
the prefab from now on.
Check over all the game objects in the prefab to ensure all the position transforms are set
to 0 , 0 , 0 . This will avoid too much head-scratching when they don't draw in the correct
place.
Return to the BattleManager game object and add the new prefab to the EnemyPrefabs
property of the BattleManager script. We need to replace the one we just deleted.
Houston, we have a problem!
Despite our best laid-out plans, we actually have problems now; if you run the project at
this point, you will notice two very annoying bugs:
• The Goblins spawn into the battle horrendously and die instantly
• Their death isn't finite as they keep dying repeatedly
Now, this isn't truly a problem for our budding adventurer and is arguably fun to watch,
but this isn't what we were really going for; there should at least be some challenge.
Mecanim AI considerations
The answer to the first problem is simple enough: it takes time for EnemyController
to update the EnemyAI state machine for the first time (several frames actually, just a Un-
ity thing). As the AI isn't updated, the initial state of EnemyHealth is 0 . So, when the
state machine starts, the initial condition for the transition to GoblinDeath is met because
EnemyHealth is less than 2 . To resolve this, simply set the default state machine's value
for EnemyHealth to something more than the default condition, as shown in the follow-
ing screenshot (for example, I set the default value to 5 ):
Search WWH ::




Custom Search