Graphics Reference
In-Depth Information
Once the attack wave is in the scene, we use GameObject.GetComponent to find the
WaveProperties script that needs to be attached to the parent gameObject of the attack
wave prefab. This script has a single variable that we need to get at: enemiesInWave. As
long as enemiesInWave is set correctly on the prefab, the wave spawner can use the vari-
able currentWave to store how many enemies the player needs to destroy to progress to
the next wave:
WaveProperties tempProps=
tempObj.GetComponent<WaveProperties>();
currentWave= tempProps.enemiesInWave;
}
Whenever an enemy is destroyed, the game-specific game controller makes a call to
the following Fragged() function (see earlier in this chapter GameController_LBS.cs):
public void Fragged()
{
We decrease the value of currentWave, which holds how many enemies are in the
current wave:
// one enemy down
currentWave--;
Then the value of currentWave is checked to see whether it is less than or equal to
0. If this is true, it must be time to spawn the next attack wave so a call goes out to the
LaunchWave() function:
if( currentWave<=0 )
{
// this wave is done, let's start the next one!
LaunchWave ();
}
}
}
11.9 Wave Properties
The Wave_Spawner.cs script outlined in the last section showed that we need to know how
many enemies there are in each attack wave. To take care of this, a simple WaveProperties
script is attached to the attack wave prefab. It contains just a single integer named enemies-
InWave that we set in the Unity editor Inspector window. The game controller script will
access this value whenever a new wave is spawned, and it will use the value of enemiesIn-
Wave to keep track of enemies in each wave.
WaveProperties.cs looks like this:
public class WaveProperties : MonoBehavior
{
public int enemiesInWave;
}
Search WWH ::




Custom Search