Advertisement
Guest User

Rock Object Pool

a guest
Oct 5th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class RockPool : MonoBehaviour {
  5.  
  6. static int numRocks = 1000;
  7. public GameObject rockPrefab;
  8. static GameObject[] rocks;
  9.  
  10. void Start ()
  11. {
  12. //Setting array size to numRocks size
  13. rocks = new GameObject [numRocks];
  14.  
  15. for (int i = 0; i < numRocks; i++)
  16. {
  17. rocks [i] = (GameObject) Instantiate(rockPrefab, Vector3.zero, Quaternion.identity);
  18. rocks [i].SetActive (false);
  19. }
  20. }
  21.  
  22.  
  23. static public GameObject getRock()
  24. {
  25. for (int i = 0; i < numRocks; i++)
  26. {
  27. if (!rocks [i].activeSelf)
  28. {
  29. return rocks [i];
  30. }
  31. }
  32. return null;
  33. }
  34.  
  35.  
  36. public void GenerateRocks()
  37. {
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement