In my very simple scene - I have 2 kinds of enemy - cylinder and sphere - one has cylinderEnemyScript and the other sphereEnemyScript
both of these scripts inherit from enemyScript:
public class EnemyScript : MonoBehaviour
{
public GameObject particle;
virtual protected void OnDestroy()
{
Instantiate(particle, transform.position - transform.up, Quaternion.identity);
}
}
so yea - once an enemy blows up a particle system gets instantiated - I have a gun that I fire projectiles from - here’s the projectileScript:
public class ProjectileScript : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
rigidbody.useGravity = true;
GetComponent<TimedDestruct>().enabled = true;
if (other.gameObject.tag == "Enemy")
{
Destroy(other.gameObject);
}
}
}
so I destroy the enemy - and on his OnDestroy() I instantiate the particle system - which is just a flame from the std assets.
I hit play and everything’s acting how it’s supposed to - but when I exit out of play - I get these Flame(Clone) instances in my hierarchy
and also get a “Some objects were not cleaned up when closing scene”
Everytime I play and exit out I get more and more instances!
why is this happening? - how to resolve it? - Thanks a lot for any help in advance