MrSpaceCow

Random Cloud Movement Unity Script 2

Aug 13th, 2016
1,754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CloudManagerScript : MonoBehaviour {
  5.     //Set this variable to your Cloud Prefab through the Inspector
  6.     public GameObject cloudPrefab;
  7.  
  8.     //Set this variable to how often you want the Cloud Manager to make clouds in seconds.
  9.     //For Example, I have this set to 2
  10.     public float delay;
  11.  
  12.     //If you ever need the clouds to stop spawning, set this variable to false, by doing: CloudManagerScript.spawnClouds = false;
  13.     public static bool spawnClouds = true;
  14.  
  15.     // Use this for initialization
  16.     void Start () {
  17.         //Begin SpawnClouds Coroutine
  18.         StartCoroutine(SpawnClouds());
  19.     }
  20.  
  21.     IEnumerator SpawnClouds() {
  22.         //This will always run
  23.         while(true) {
  24.             //Only spawn clouds if the boolean spawnClouds is true
  25.             while(spawnClouds) {
  26.                 //Instantiate Cloud Prefab and then wait for specified delay, and then repeat
  27.                 Instantiate(cloudPrefab);
  28.                 yield return new WaitForSeconds(delay);
  29.             }
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment