My very different solution that worked for me

I knew my solution was going to be different when I un-paused the Challenge and heard the lecturer say we don’t need Update() lol I had gone into a deep dive on using “Find”. the only thing my solution did not do was introduce a timer. My explosions were far enough apart that I did not notice a need for a delay.

=================
public class SelfDestruct : MonoBehaviour

{

Transform VFXExplosionClone;  

private void Update()

{

  DestroyVFXExplosion();

}    

void DestroyVFXExplosion()

{        

    VFXExplosionClone = transform.Find("Enemy Explosion VFX(Clone)");

    if(transform.Find("Enemy Explosion VFX(Clone)")  != null)

    {          

      Destroy(VFXExplosionClone.gameObject);        

    }

}

}

3 Likes

Awesome job for solving it on your own. There is multiple solutions and one way is not always better or worse than others. Great job.

I also used the update, but in a more performanced way.
Because .Find is pretty ‘heavy’ I heard so having a .find in the update is generally a bad idea.

I get the component in the start, and when it stopped, I destroy it.

public class SelfDestruct : MonoBehaviour
{
[SerializeField] float timeTillDestroy = 3f;

ParticleSystem particleSystem;

private void Start()
{
    //  Destroy(gameObject, timeTillDestroy);
    particleSystem = GetComponent<ParticleSystem>();
}


void Update()   
{
    if (particleSystem.isStopped)
    {
        Destroy(gameObject);
    }
}

}

1 Like

Privacy & Terms