-
Notifications
You must be signed in to change notification settings - Fork 5
/
ObjectPoolSimple.cs
39 lines (32 loc) · 1.03 KB
/
ObjectPoolSimple.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectPoolSimple : MonoBehaviour
{
public GameObject prefabGameObject;
public int pooledAmount;
[HideInInspector] public List<GameObject> objects;
void Awake()
{
for (int i = 0; i < pooledAmount; i++)
{
GameObject obj = (GameObject)Instantiate(prefabGameObject);
obj.transform.parent = gameObject.transform;
obj.SetActive(false);
objects.Add(obj);
}
}
}
/* Use Pool
[SerializeField]private ObjectPoolSimple _ObjectPool;
private void Spawn() {
for (int i = 0; i < _ObjectPool.objects.Count; i++) {
if (!_ObjectPool.objects[i].activeInHierarchy) {
_ObjectPool.objects[i].transform.position = new Vector3(0,0,0);
_ObjectPool.objects[i].transform.rotation = Quaternion.Euler(0, 0, 0);
_ObjectPool.objects[i].SetActive(true);
break;
}
}
}
*/