Graphics Reference
In-Depth Information
if( currentWave<=0 )
{
// this wave is done, let's start the next one!
LaunchWave ();
}
}
}
11.8.1 Script Breakdown
The way attack waves are made in Lazer Blast Survival is by having a preset layout of
enemies made previously in the Unity editor, parented to a single gameObject and saved
out as a single prefab. When it comes time to add a new wave of enemies to the scene, the
prefab is instantiated and the wave spawner script keeps track of how many enemies there
are until it is time to spawn new ones.
This is an arena-based shooter and the action is intended to go on and on until the
player runs out of lives. In this example game, there are just a few enemy wave prefabs
(meaning that there are only just a few different types of attack waves), but there could just
as easily be tens or hundreds of different layouts as required. The array spawnObjectPrefabs
contains references to all of the attack wave prefabs.
Wave_Spawner.cs derives from MonoBehavior to take advantage of some of Unity's
built-in function calls:
using UnityEngine;
using System.Collections;
public class Wave_Spawner : MonoBehavior
{
When the Start() function is called, the first thing that happens is that all of the attack
wave prefabs are counted and the result stored in the integer variable totalSpawnObjects:
void Start ()
{
// count how many objects we have lined up in the spawn
// object list
foreach( GameObject go in spawnObjectPrefabs )
{
totalSpawnObjects++;
}
Debug.Log("Wave_Spawner.cs found "+totalSpawnObjects+" spawn
objects to choose from.");
Once counting has finished, the first attack wave is scheduled using timeBeforeFirst-
Spawn to tell the Invoke statement how long to wait:
// schedule first attack wave
Invoke("LaunchWave",timeBeforeFirstSpawn);
}
Search WWH ::




Custom Search