Quantcast
Channel: Answers by "podmaster"
Viewing all articles
Browse latest Browse all 30

Answer by podmaster

$
0
0
Well i decided to give up and just get reference to the pool script for now i don't have so many spawn objects. I leave the code for anyone how is working on pooling Objects as an alternative. I create a list of individual pools with different GameObjects Quantities and Grow or not variables. Just create an Object attach the script and then call LoadObject(IndexOfThePool) and use it. //CREAR PILETAS DINAMICAS =START= public class ObjectsPool extends System.Object { var Objeto : GameObject; //Prefab or object to instantiate var Cantidad : int; //Quantity var Escalable : boolean; //Will Grow? var Pileta = new List.(); //Actual list of Pooled objects } var GrupoDePiletas : ObjectsPool[];// Group of pools //Init the pool with the specified quantities and objects function Start () { for(var piletas : ObjectsPool in GrupoDePiletas){ for(var i = 0;i < piletas.Cantidad;i++){ var obj = Instantiate(piletas.Objeto,Vector3(0,0,0),Quaternion.identity); obj.SetActive(false); piletas.Pileta.Add(obj); } } } //CREAR PILETAS DINAMICAS =END= //Use this function to get an object from an specific pool //For example Pool[0] Enemies , Pool[1] Bullets , Pool[2] Clouds... function LoadObject(PoolNumber : int) { for(var i = 0;i < GrupoDePiletas[PoolNumber].Pileta.Count;i++){ if(!GrupoDePiletas[PoolNumber].Pileta[i].activeInHierarchy){ return GrupoDePiletas[PoolNumber].Pileta[i]; }else if(GrupoDePiletas[PoolNumber].Pileta[i].activeInHierarchy && i == GrupoDePiletas[PoolNumber].Pileta.Count-1 && GrupoDePiletas[PoolNumber].Escalable){ var obj = Instantiate(GrupoDePiletas[PoolNumber].Objeto,Vector3(0,0,0),Quaternion.identity); obj.SetActive(false); GrupoDePiletas[PoolNumber].Pileta.Add(obj); return obj; } } return null; }

Viewing all articles
Browse latest Browse all 30

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>