public void Deactivate(bool returnToPool) { if (returnToPool) { pool.InsertObject(this.gameObject); } active = false; gameObject.SetActive(false); }
// Use this for initialization void Start() { muzzle = transform.Find("Muzzle"); projectilePool = gameObject.AddComponent <ObjectsPool> (); projectilePool.poolObject = projectile; projectilePool.poolObjects = new List <GameObject>(); for (int i = 0; i < (int)(ammoCapacity * 1.5f); i++) { GameObject newProjectile = Instantiate(projectile, projectilePool.transform.position, projectilePool.transform.rotation); PoolProjectile newPoolProjectile = newProjectile.GetComponent <PoolProjectile>(); newPoolProjectile.poolObject = newProjectile.GetComponent <PoolObject>(); if (newPoolProjectile.poolObject == null) { newPoolProjectile.poolObject = newProjectile.AddComponent <PoolObject>(); } newPoolProjectile.poolObject.pool = projectilePool; newPoolProjectile.poolObject.Deactivate(); projectilePool.InsertObject(newProjectile); } }