Graphics Reference
In-Depth Information
Init() is responsible for setting up the references required to make the core of this class
work. Those are the transform of the gameObject this script is attached to and the trans-
form belonging to the main camera in the scene (found by using Unity's Camera.main):
void Init ()
{
// cache ref to our transform
myTransform = transform;
// cache ref to the camera
Camera mainCam = Camera.main;
Camera.main finds the first camera tagged with the MainCamera tag (see the tag
dropdown in the Unity editor Inspector window). If there are no cameras in the scene
tagged with this, the main part of this function will not work. For that reason, when main-
Cam is null, it drops out of Init() early:
if( mainCam==null )
return;
The camera transform is stored in cameraTransform, which will be used to trigger
spawning when distanceBasedSpawnStart is true:
cameraTransform = mainCam.transform;
This script has its own shouldReversePath Boolean variable, as well as the waypoint
controller having one. This line takes the value of the Boolean variable shouldReversePath
and uses it to override the existing reverse mode value held by the waypoint controller
any spawned objects will use. It does this by calling waypointControl.SetReverseMode():
// tell waypoint controller if we want to reverse the path
// or not
waypointControl.SetReverseMode(shouldReversePath);
To keep a total on how many objects are in the spawnObjectPrefabs array:
totalSpawnObjects= spawnObjectPrefabs.Length;
If shouldAutoStartSpawningOnLoad is set to true, the first spawning kicks off right away.
The StartWave() function takes two parameters: how many enemies it should spawn and
what the time between spawns should be from here on. StartWave() will schedule future
enemy spawning:
if(shouldAutoStartSpawningOnLoad)
StartWave(totalAmountToSpawn,timeBetweenSpawns);
}
The OnDrawGizmosSelected() function draws helper graphics in the Unity editor
whenever this gameObject is selected:
public void OnDrawGizmosSelected()
{
Search WWH ::




Custom Search