Skip to content

Instantly share code, notes, and snippets.

@crilleengvall
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crilleengvall/2e2c0eec451666bef514 to your computer and use it in GitHub Desktop.
Save crilleengvall/2e2c0eec451666bef514 to your computer and use it in GitHub Desktop.
StartCoroutine and StopCoroutine
using UnityEngine;
using System.Collections;
public class EnvironmentSpawner : MonoBehaviour {
public GameObject LargeCloud;
void Start() {
StartCoroutine(SpawnLargeClouds());
}
void HaltSpawning() {
StopCoroutine(SpawnLargeClouds());
}
IEnumerator SpawnLargeClouds() {
yield return new WaitForSeconds(3);
while(true) {
var largeCloud = GameObjectPooler.Instance.GetObject(LargeCloud);
largeCloud.transform.position = new Vector3(0.98f, 5.68f, -0f);
largeCloud.transform.rotation = Quaternion.identity;
largeCloud.SetActive(true);
yield return new WaitForSeconds(3);
}
}
}
using UnityEngine;
using System.Collections;
public class EnvironmentSpawner : MonoBehaviour {
public GameObject LargeCloud;
private IEnumerator _LargeCloudsRoutine;
void Start() {
this._LargeCloudsRoutine = SpawnLargeClouds();
StartCoroutine(this._LargeCloudsRoutine);
}
void HaltSpawning() {
StopCoroutine(this._LargeCloudsRoutine);
}
IEnumerator SpawnLargeClouds() {
yield return new WaitForSeconds(3);
while(true) {
var largeCloud = GameObjectPooler.Instance.GetObject(LargeCloud);
largeCloud.transform.position = new Vector3(0.98f, 5.68f, -0f);
largeCloud.transform.rotation = Quaternion.identity;
largeCloud.SetActive(true);
yield return new WaitForSeconds(3);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment