Game Development Reference
In-Depth Information
// Set the beginning battle phase
phase = BattlePhase.PlayerAttack;
}
Note
As this is a one-time coroutine, we are just initializing it with the method definition in-
stead of the string name of the method. There is no need to stop it since it only runs till all
the Goblins are in the scene and then stops.
Keeping things simple for now, we generate a random number of Goblins who will attack
(or be found wandering round the wood waiting to be chopped). Then, we spawn them in
using a coroutine and start battle with the player going first.
Note
Since we simply need a fixed random number and we are only doing it at the beginning of
the scene, we are just using the Unity Random function. If we needed a more complex
random selection or more frequent selection, we would change this to something more
complex or preloaded.
Now that we know how many Goblins we need in the battle, we can spawn them in. I've
used a coroutine here so we can animate them one by one as follows:
IEnumerator SpawnEnemies()
{
// Spawn enemies in over time
for (int i = 0; i < enemyCount; i++)
{
var newEnemy =
(GameObject)Instantiate(EnemyPrefabs[0]);
newEnemy.transform.position = new Vector3(10,
-1, 0);
yield return StartCoroutine(
MoveCharacterToPoint(
EnemySpawnPoints[i], newEnemy));
newEnemy.transform.parent =
EnemySpawnPoints[i].transform;
Search WWH ::




Custom Search