public void RemoveLastSpawned() { if (lastSpawned) { clothPool.ReturnToPool(lastSpawned); lastSpawned = null; } }
public void Spawn(int number) { if (!lastSpawned || lastSpawned.number != number) { RemoveLastSpawned(); PoolableCloth instance = clothPool.GetPrefabInstance(number); //instance.transform.position = transform.position; // set instance transform position to model position lastSpawned = instance; } }
// returns instance of prefab public PoolableCloth GetPrefabInstance(int number) { PoolableCloth instance; if (reusableInstances[number]) { instance = reusableInstances[number]; instance.gameObject.SetActive(true); } else { instance = Instantiate(prefabs[number], PoolableCloth.GetParentTransform(number)); instance.AttachColliders(); } return(instance); }
//returns prefab to pool public void ReturnToPool(PoolableCloth instance) { instance.gameObject.SetActive(false); // reset size and stretchiness reusableInstances[instance.number] = instance; }