Files
MiniGungeon/Assets/Scripts/ObjectPool.cs

46 lines
1022 B
C#

using NUnit.Framework;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPool : MonoBehaviour
{
public GameObject prefab;
public Transform parent;
public int maxObject = 30;
List<GameObject> _pool;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_pool = new List<GameObject>();
for(int i = 0; i < maxObject; i++)
{
//GameObject obj = Instantiate(prefab);
GameObject obj = Instantiate(prefab, parent);
obj.SetActive(false); // ??? ?????? ??? ??????? ???? ??? ????
_pool.Add(obj);
}
}
public GameObject Get()
{
foreach(GameObject obj in _pool)
{
if(!obj.activeInHierarchy)
{
obj.SetActive(true);
return obj;
}
}
return null;
}
// Update is called once per frame
void Update()
{
}
}