#ok so the explosion is the gameobject
1 messages · Page 1 of 1 (latest)
Your Explosion component is attached to a GameObject
there is also a ParticleSystem on that GameObject
ye
Your code is only destroying the ParticleSystem
leaving everything else behind
You're instantiating a prefab, right?
yes
Then your script will be affecting just the instance that was created
so destroying that GameObject will get rid of the instance
okay and i dont understand how do i get the other instances
i am creating them with instantiate, no?
Yes, and then each one is, individually, going to destroy itself when it's done, right?
Because it's only destroying the particle system
The game object has several components on it -- the particle system, your explosion script, and maybe some others
If you do Destroy(particleSystem), you will only destroy the particle system component
The explosion script will still be attached, and the entire game object will still exist
yeah i dont wanna destroy the game object because its a gamemanager
Is it really, though?
I thought you were instantiating explosion prefabs.
ah, I see the confusion
yes it would be better from another script but i cant change the prefab script anymore
you're thinking I'm saying to do this
Destroy(gameObject);
I was also a bit confused; I thought that the Destroy was being run by the explosion prefab
but no, it's being run by the manager script
Consider this:
Destroy(explosionInstance.gameObject, 2);
this will tell Unity to destroy the entire explosion object in 2 seconds
i tried this with LifeToKill script too but no effect
ah
i thought the particle system is the same as a gameobject already
ah, no, they are distinct
ParticleSystem is a component
You can Destroy() any kind of unity Object
it tells me this
Show me what code you ran
you may have done Destroy(explosion.gameObject);
yes
that tried to destroy the prefab
which Unity doesn't let you do, so that you don't actually lose the asset
explosionInstance is a reference to the ParticleSystem on the prefab you just created
that would be a crazy mistake lol
yeah, you can do a lot of damage if you start messing with the assets themselves :p
but there are guardrails, like the one you saw
interesting
(you can't destroy the transform, though; that's not allowed)