ObjectPool

Posted 2020. 10. 13. 16:24

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObjectPool
{
    Queue<GameObject> q = new Queue<GameObject>();

public ObjectPool()
    {


    }
    public GameObject GetObject()
    {
        if (q.Count > 0)
        {
            GameObject g = q.Dequeue();
            g.SetActive(true);
            return g;
        }
        else
            return null;

    }
    public void SetObject(GameObject g)
    {
        g.SetActive(false);
        q.Enqueue(g);


    }

}