Graphics Reference
In-Depth Information
Once the color has been set by Gizmos.color, everything drawn after this point will
adopt the set color:
Gizmos.color = new Color(0,0,1,0.5f);
Gizmos.DrawCube() is used here to display a cube to show how close the cam-
era will need to be in order to trigger the spawning. This is based on the value of
distanceFromCameraToSpawnAt:
Gizmos.DrawCube(transform.position,new Vector3(200,0,distance
FromCameraToSpawnAt));
}
The main reason that this script derives from MonoBehavior is so that it can use the
system functions such as Update(). The Update() function is called every frame:
public void Update()
{
aDist is a temporary float variable used to figure out the difference between this trans-
for m's z position and the position of the camera. It uses the z position (and not the other
axis) because of the way that the camera moves through the level. The camera progresses
through the level along the world z -axis, so for the type of game this system is designed for
it makes sense to use only the z -axis:
float aDist= Mathf.Abs(myTransform.position.z-camera
Transform.position.z);
If the component is set to use distanceBasedSpawnStart, there is no spawning cur-
rently happening and the distance is less than distanceFromCameraToSpawnAt, the next
wave can be spawned:
if( distanceBasedSpawnStart && !spawning && aDist<distance
FromCameraToSpawnAt)
{
StartWave(totalAmountToSpawn,timeBetweenSpawns);
spawning=true;
}
}
StartWave() begins by resetting a few variables that will be used during the spawn cycle.
A counter is used to track of the number of enemies spawned (spawnCounter), and the param-
eter named HowMany is copied into another variable, totalAmountToSpawn, to track
how many this wave should contain:
public void StartWave(int HowMany, float timeBetweenSpawns)
{
spawnCounter=0;
totalAmountToSpawn=HowMany;
// reset
currentObjectNum=0;
Search WWH ::




Custom Search