- Home /
How to Destroy A single Particle
hopefully this picture helps give you a visual of what am trying to do
currently I have a game object with a sphere collider as a trigger and a particle system (Shuriken)
I then add another script that must remove particles as they exit the trigger. Am having a hard time figuring out how to do this with any particle that exits the sphere to remove from the array list of that particular particle system
I know I must somehow use functions GetParticles , and SetParticles to do this Any clues or help would be very much appreciated
I think I need to -Grab access the array of the particle system -find the correct particle that exited -delete it -set the new array back without the deleted particle
My questions are -how do I know which particle that left what index -how to remove the particular particle -and set the correct particle array back
this is what i currently have that am using to get a deeper understanding on how to access all the info i need to achieve what i want.
public class BlastRadius : MonoBehaviour {
Particle [] particleArray;
int particleCount;
void Start () {
particleArray = new Particle[particleCount];
}
// using to understand how info is stored within the particle system
void Update () {
particleCount = gameObject.particleSystem.particleCount;
particleArray = new Particle[ particleCount ];
//Debug.Log(particleCount );
// Debug.Log ( particleArray);
}
//removes partical on exit
void OnTriggerExit( Collider col ){
removeParticle();
}
void findParticle(){
//somehow find the particular particle i want to destroy
}
void removeParticle(){
//then remove it
//remove(findParticle());
}
}
Answer by thef1chesser · Oct 24, 2013 at 08:42 AM
Well to destroy a particle.
UnityEngine.Object.Destroy(particle);
Edit: if you just want to destroy the other particle
OnTriggerExit(Collider col) { UnityEngine.Object.Destroy(col.collider); }
I tried adding that but it didn't remove the particle correctly it still was there floating off into the distance >:P
what if you rebuild it in such a way taht the particles themselves check if they have exited the sphere.
so the particles have the OnTriggerExit and you just say
UnityEngine.Object.Destroy(this);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Destroy particles based on bounds not lifetime 0 Answers
Distribute terrain in zones 3 Answers
how can I get particle.position out of shuriken system? 2 Answers
Particle System Using Code 0 Answers