Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GameController : MonoBehaviour {
- delegate void DoSpawn();
- DoSpawn doMySpawn;
- public GameObject hazard;
- public Vector3 spawnValues = new Vector3(6, 0, 16);
- public float spawnWait = .5f;
- public float wait = 1;
- float nextTime;
- // Use this for initialization
- void Start ()
- {
- nextTime = Time.time + wait;
- doMySpawn = Do1;
- }
- void SpawnWaves()
- {
- Vector3 spawnPosition = new Vector3(
- Random.Range(-spawnValues.x, spawnValues.x),
- spawnValues.y, spawnValues.z);
- Quaternion spawnRotation = Quaternion.identity;
- Instantiate(hazard, spawnPosition, spawnRotation);
- }
- void Do1()
- {
- if (Time.time > nextTime)
- {
- Do2();
- doMySpawn = Do2;
- }
- }
- void Do2()
- {
- if (Time.time > nextTime)
- {
- nextTime = Time.time + spawnWait;
- SpawnWaves();
- }
- }
- // Update is called once per frame
- void Update () {
- doMySpawn();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement