-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjPool.cs
48 lines (43 loc) · 1.11 KB
/
ObjPool.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
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjPool : MonoBehaviour
{
public int numberOfObjs = 6;
public GameObject _pistola;
private List<GameObject> pistolaList;
public GameObject _shotgun;
private List<GameObject> shotgunList;
void Start()
{
pistolaList = new List<GameObject>();
shotgunList = new List<GameObject>();
}
/////////// Aramas ///////////////
public GameObject Pistola()
{
int numberOfObjs = pistolaList.Count;
for (int i = 0; i < numberOfObjs; i++)
{
if (!pistolaList[i].activeInHierarchy)
return pistolaList[i];
}
GameObject obj = Instantiate(_pistola);
obj.SetActive(true);
pistolaList.Add(obj);
return obj;
}
public GameObject Shotgun()
{
int numberOfObjs = shotgunList.Count;
for (int i = 0; i < numberOfObjs; i++)
{
if (!shotgunList[i].activeInHierarchy)
return shotgunList[i];
}
GameObject obj = Instantiate(_shotgun);
obj.SetActive(true);
shotgunList.Add(obj);
return obj;
}
}