Hi! I have a base class for my physical objects. It has an update method like in the code below.
public class PhysicsObjectBase : MonoBehaviour
{
public virtual void Update()
{
if (transform.position.y < GameManager.Instance.DestroyObjectsThreshold)
{
Destroy(gameObject);
}
}
}
I have a child class for this which does its own logic and then calls base.Update(). This class also has a coroutine which is called when the object has 0 HP left.
public class DestructibleBase : PhysicsObjectBase
{
public override void Update()
{
if (DrawExplosionPosition)
{
DrawExplodePosition();
}
base.Update();
}
...
protected IEnumerator DestroyChunksAndGameObject()
{
yield return new WaitForSeconds(DestroyAfterExplosionTime);
var alpha = 1.0f;
foreach (var chunk in _chunks)
{
// do some stuff
}
...
foreach (var chunk in _chunks)
{
Destroy(chunk.gameObject);
}
Destroy(gameObject);
yield return null;
}
However, when calling base.Update() the coroutine will never continue after yield return new WaitForSeconds(DestroyAfterExplosionTime);. It will execute that line though, but never resume execution.
If I remove the call to base.Update() everything works as expected again. I cannot figure out why the coroutine stops executing, anyone have any idea?
Have a nice day!