Game Development Reference
In-Depth Information
public GameObject[] EnemySpawnPoints;
public GameObject[] EnemyPrefabs;
public AnimationCurve SpawnAnimationCurve;
These lines maintain the spawn points the battle manager knows about, the possible en-
emy prefabs it can spawn into the scene, and a curve that we can use later to control how
we animate the Goblins. More on this later.
Next, we have some control variables to manage the battle as it ensues. This is done using
the following code:
private int enemyCount;
enum BattlePhase
{
PlayerAttack,
EnemyAttack
}
private BattlePhase phase;
Note
These states are only temporary. In Chapter 9 , Getting Ready to Fight , and Chapter 10 ,
The Battle Begins , we will build on this for a more full-fledged system using Mecanim.
We keep a count of how many enemies are active in the scene as well as what phase the
battle is in at the moment (along with our own enumeration of the states the battle can be
in; you can always add more). Finally, we have a flag to monitor whether the enemy char-
acters have actually started fighting.
Now when the script is run, it needs to initialize the battle arena; so add the following
code to the Start method:
void Start () {
// Calculate how many enemies
enemyCount = Random.Range(1,
EnemySpawnPoints.Length);
// Spawn the enemies in
StartCoroutine(SpawnEnemies);
Search WWH ::




Custom Search