Right now the projectile is generating SFX, but upon impact, when the gameObject is destroyed, the sound source also gets destroyed.
You can solve this by not destroying the projectile gameobject but rather, delaying it by a few seconds.
I’ve added a foreach loop to destroy 2 objects & the gameobject prefab:
- for the object to destroy upon impact
- to destroy the particle effect that gets destroyed slightly later after impact
- destroy the entire gameobject after a few seconds.
Here’s the code snippet: (add serialize field for the gameObject to destroyAfterHit)
foreach (GameObject toDestroy in destroyOnHit)
{
Destroy(toDestroy);
}
foreach (GameObject toDestroy in destroyAfterHit)
{
Destroy(toDestroy, destroyAfterHitTime);
}
Destroy(gameObject, lifeAfterImpact);