Last active
August 29, 2015 14:17
-
-
Save crilleengvall/2e2c0eec451666bef514 to your computer and use it in GitHub Desktop.
StartCoroutine and StopCoroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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