탑뷰 슈팅 게임 미니 프로젝트
This commit is contained in:
45
Assets/Scripts/ObjectPool.cs
Normal file
45
Assets/Scripts/ObjectPool.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user