Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ObjectPools : MonoBehaviour
  6. {
  7. public CoinRotate Coin;
  8. private Queue<CoinRotate> Items = new Queue<CoinRotate>();
  9. public static ObjectPools Instance {get; set;}
  10. private void Awake(){
  11. Instance = this;
  12. }
  13. public CoinRotate Get(){
  14. if(Items.Count == 0){
  15. CoinRotate obstacle = Instantiate(Coin);
  16. obstacle.gameObject.SetActive(false);
  17. Items.Enqueue(obstacle);
  18. }
  19. return Items.Dequeue();
  20.  
  21. }
  22. public void ReturnToPool(CoinRotate obj){
  23. obj.gameObject.SetActive(false);
  24. Items.Enqueue(obj);
  25. }
  26. void Start()
  27. {
  28.  
  29. }
  30.  
  31.  
  32. void Update()
  33. {
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement