Now to create a game controller start by making a new game object and name it Game Controller and set it to origin position and change the tag to Game Controller and add component, new script and name it game controller, now edit the game controller script.
Public class GameController : MonoBehaviour
{
Public GameObject hazard;
Public Vector3 spawnValues;
Public inthazardCount;
Public float spawnWait;
Public float startWait;
Void start ()
{
StartCoroutine (SpawnWaves ());
}
IEnumerator SpawnWaves ()
{
Yield return new WaitForSeconds (startWait);
while (true)
{
For (int I = 0; i < hazardCount; i++)
{
Vector3 spawnPosition = new vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate (hazard, spawnPosition. spawnRotation);
Yield return new WaitForSeconds (spawnWait);
}
Yield return new WaitForSeconds (waveWait);
}
}
}
Select the Game Controller in the hierarchy and drag the prefab Asteroid onto the hazard slot in the inspector to create the reference then set the spawn value Z to 16 and the spawn values X to 6, set the hazard count to 10. This code also allows me to alter the spawn times of  the asteroids so they aren’t just one big clump of death, so in the inspector set the spawn wait to 0.5 and the start wait  1 then change the wave wait to 4 which means 4 seconds will pass before the next wave is spawned.

Comments

Popular posts from this blog