Getting Particle System from serialized Hit effect

It was really interesting seeing Rick’s solution to the first bit of the challenge. I had no idea that the Hit Effect would be able to ‘see’ the Particle System on the Projectile using a GetComponent call.
I had thought GetComponent would only find a thing on the same game object. But here, the Hit Effect is not a child of the Particle at all. It’s just a serialized field that is instantiated. I guess that gives it access somehow?
Interesting!

The DestroyAfterEffect script should be placed on the HitEffect Prefab itself, not on the Projectile. That prefab should have a ParticleSystem on it (if it doesn’t, it will cause a null reference error!). That’s why the GetComponent call works. Projectile itself could get access to the instantiated HitEffect by caching the result of the instantiation, but there’s no real need since the DestroyAfterEffect script will take care of things for us.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms