Language: C#
Goal: Only call a function if the object being returned to it is NOT null.
Current Progress: I’m setting up Object Pooling with my PlayerWeaponFire script. The ObjectPool script has a Activate() function that returns the current GameObject its searching for in its for loop.
public GameObject ActivateObject()
{
for (int i = 0; i < poolSize; i++)
{
if (objects*.activeInHierarchy == false)*
-
{*
_ objects*.SetActive(true);_
_ avaiableObject = true;_
_ return objects;
}
}
return null;
}*
My PlayerWeaponFire script then calls this ActivateObject() function to enable a bullet in the ObjectPool._
* IEnumerator FirePrimary ()*
* {*
* ObjectStats playerStats = GetComponent();*
* if (Time.time > nextPrimaryFire)*
* {*
* nextPrimaryFire = Time.time + primaryFireRate;*
* {*
* for(int i = 0 ; i < primaryNumberOfShots; i++)*
* {*
* Activate(primaryPool);*
* playerStats.currentAmmo = playerStats.currentAmmo - primaryAmmoCost;*
* yield return new WaitForSeconds (primaryShotInterval);*
* }*
* }*
* } *
* }*
Need: I need to be able to skip over the Activate() function if the GameObject being returned to it is null.