Don't forget to cleanup after the effect has played!

There’s this neat little setting for particle systems where you can define a “Stop Action” and set it to “Destroy”, so a one-off particle effect will clean up after itself :wink:

Also, I didn’t think so much about using GetAimLocation(). Instead I did it like this:

            if (null != hitEffect)
                Vector3 closestPoint = other.ClosestPoint(transform.position);
                GameObject effect = Instantiate(hitEffect, closestPoint, transform.rotation);
                effect.transform.parent = null;

Note that I explicitly set the effect’s parent to null, so effectively decoupling it from the projectile so the particle effect can play to its end while the projectile is already destroyed.
(OTOH I defined a delay for destroying projectiles, so an arrow sticks in its target for a moment before it disappears…)

Privacy & Terms