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 DoWork();
- DoWork doMyWork;
- public GameObject hazard;
- public Vector3 spawnValues = new Vector3(6, 0, 16);
- public float spawnWait = .5f;
- public float wait = 1;
- public int hazardCount = 10;
- float nextTime;
- // Use this for initialization
- void Start ()
- {
- nextTime = Time.time + wait;
- doMyWork = SpawnWaves;
- }
- void SpawnWaves()
- {
- if (hazardCount > 0 && Time.time > nextTime)
- {
- hazardCount--;
- nextTime = Time.time + spawnWait;
- Vector3 spawnPosition = new Vector3(
- Random.Range(-spawnValues.x, spawnValues.x),
- spawnValues.y, spawnValues.z);
- Quaternion spawnRotation = Quaternion.identity;
- Instantiate(hazard, spawnPosition, spawnRotation);
- }
- else if (hazardCount < 1)
- {
- doMyWork = EmptyDo;
- }
- }
- void EmptyDo()
- {
- }
- // Update is called once per frame
- void Update()
- {
- // делегат
- doMyWork();
- }
- }
- ///////////////////////
- /////////
- // место вот этого что предлагают в уроке - через Абстрактное АПИ
- // и хитрые конструкции....
- ///
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement