// Use this for initialization void Start() { for (int i = 0; i < amountFirst; i++) { VKObjectPool nOIP = CreateObject(); nOIP.gameObject.SetActive(false); } }
private VKObjectPool CreateObject() { GameObject nObj = (GameObject)Instantiate(prefab, hidePosition, prefab.transform.rotation); nObj.name = nObj.name + "" + count; count++; nObj.transform.SetParent(this.transform); nObj.transform.localPosition = hidePosition; nObj.transform.localScale = new Vector3(1f, 1f, 1f); VKObjectPool nOIP = nObj.GetComponent <VKObjectPool>(); nOIP.isUsing = false; pool.Add(nOIP); return(nOIP); }
public T BorrowObject <T>() { foreach (VKObjectPool obj in pool) { if (!obj.isUsing) { obj.gameObject.SetActive(true); obj.isUsing = true; return(obj.gameObject.GetComponent <T>()); } } VKObjectPool nOIP = CreateObject(); nOIP.gameObject.SetActive(true); nOIP.isUsing = true; return(nOIP.gameObject.GetComponent <T>()); }