PoolManager.ReuseObject C# (CSharp) Method

ReuseObject() public method

public ReuseObject ( GameObject prefab, Vector3 position, Quaternion rotation ) : void
prefab GameObject
position Vector3
rotation Quaternion
return void
	public void ReuseObject(GameObject prefab, Vector3 position, Quaternion rotation) {
		int poolKey = prefab.GetInstanceID ();

		if (poolDictionary.ContainsKey (poolKey)) {
			ObjectInstance objectToReuse = poolDictionary [poolKey].Dequeue ();
			poolDictionary [poolKey].Enqueue (objectToReuse);

			objectToReuse.Reuse (position, rotation);
		}
	}

Usage Example

    public void FireBullet(float angle)
    {
        /*
         * //Debug.Log("Fire");
         * //Vector3 eulers = lookRot.eulerAngles;
         * Quaternion rot = Quaternion.Euler(0, lookRot, 0);
         *
         * BulletController temp = Instantiate(tower.bulletPrefab, (Vector3)position + lookRot * firingHarness.transform.position, rot).GetComponent<BulletController>();
         * Rigidbody rigidbody = temp.GetComponent<Rigidbody>();
         * temp.damage = tower.damage;
         *
         * rigidbody.velocity = rot * (Vector2.up * 10);*/

        Quaternion rot = Quaternion.Euler(0, angle, 90);
        //BulletController temp = Instantiate(tower.bulletPrefab, firingHarnesses[currentFiringHarness++].transform.position, Quaternion.Euler(0, angle, 0)).GetComponentInChildren<BulletController>();
        GameObject       tempParent = PoolManager.ReuseObject(tower.bulletPrefab, firingHarnesses[currentFiringHarness++].transform.position, rot);
        BulletController temp       = tempParent.GetComponentInChildren <BulletController>();

        temp.parent = tempParent;
        Rigidbody tempRbody = temp.GetComponentInChildren <Rigidbody>();

        temp.rbody         = tempRbody;
        tempRbody.velocity = Quaternion.Euler(0, angle - 90, 0) * (Vector3.forward * tower.bulletVelocity);
        temp.tower         = this;

        currentFiringHarness = currentFiringHarness % firingHarnesses.Length;

        /*if (firingHarnesses.Length >= currentFiringHarness)
         *  currentFiringHarness = 0;*/

        if (tower.attackSpeed != 0f)
        {
            nextFireTime = Time.time + (1f / tower.attackSpeed);
        }
    }
All Usage Examples Of PoolManager::ReuseObject