- Home /
How do I destroy player when colliding with looping particle system (Explosion)
I have a simple player script that moves a capsule 1 unit at a time with WASD and a 2 second looping explosion particle system in a 1 by 1 grid.
Basically, if the player is inside the 1 by 1 grid with the particle system when the explosion goes off I want to destroy the player capsule(really want it to play a death sequence/animation). I am guessing it should be simple but how do I do this?
Hi. Why don't you attach a trigger collider and a tag to the particle system and you check for collision between the player and that tag?
So, if I did that would the collider check for collision between the player and the explosion particle system at all times or just when the explosion occurs? How can I check at just the first frame of the explosion?
It would check at all times, but you could check, if the explosion occurs, by checking if it's enabled: look here Now you are able to write a script, which handles the collision detection of the player. Then the script could check if the collision object has the specific tag. If so, you could grab the particle system component and look if it's enabled. Hope it helps and happy coding.
Basically, your explosion is generated by a script and you can initially set a bool to false. When the explosion occurs, set that bool to true, and back to false after a certain amount of time. Then, execute the code that kills or destroys the player only if that bool is true.You could achieve this with a Coroutine and WaitForSeconds. If you want any code, please post your code so we can help you.
So right now I just have a particle system and a material with it. It's actually a particle system from the unity sample particle pack on the asset store. But anyways, I dont see any script attached to it.