Advertisement
Guest User

MountainSpawner

a guest
Oct 28th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1.     public GameObject mountains;
  2.  
  3.     public float mountainSpawnRateMax;
  4.     public float mountainSpawnRateMin;
  5.  
  6.     public float maxZ;
  7.     public float minZ;
  8.  
  9.     public float maxScalex;
  10.     public float minScalex;
  11.  
  12.     public float maxScaley;
  13.     public float minScaley;
  14.  
  15.     public float mountainSpeed;
  16.  
  17.     bool t;
  18.  
  19.     void OnEnable()
  20.     {
  21.         Rigidbody2D[] m = GetComponentsInChildren<Rigidbody2D>();
  22.         foreach (Rigidbody2D mnt in m)
  23.         {
  24.             mnt.velocity = new Vector3(-1 * mountainSpeed, 0, 0);
  25.         }
  26.         t = true;
  27.         Invoke("SpawnMountain", Random.Range(mountainSpawnRateMin, mountainSpawnRateMax));
  28.     }
  29.  
  30.     void OnDisable()
  31.     {
  32.         t = false;
  33.     }
  34.  
  35.     void SpawnMountain()
  36.     {
  37.         float ranZ = Random.Range(minZ, maxZ);
  38.         Vector3 spawnPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + ranZ);
  39.         GameObject mountain = Instantiate(mountains, spawnPos, Quaternion.identity) as GameObject;
  40.         mountain.GetComponent<Rigidbody2D>().velocity = new Vector3(-1 * mountainSpeed, 0, 0);
  41.         mountain.transform.parent = transform;
  42.         float ranScalex = Random.Range(minScalex, maxScalex);
  43.         float ranScaley = Random.Range(minScaley, maxScaley);
  44.         mountain.transform.localScale -= new Vector3(ranScalex, ranScaley, 0);
  45.         if(t == true)
  46.         {
  47.             Invoke("SpawnMountain", Random.Range(mountainSpawnRateMin, mountainSpawnRateMax));
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement