[c#] how to keep particles alive after destroying parent?
So i have my main object and then a particle system as a child.
On triggerEnter i want to destroy the actual main object but keep the particles until they are gone on their own
private void OnTriggerEnter(Collider other)
{
Destroy(this.gameObject);
}
this is what i have so far, thanks!
Answer by z0code0z · Jun 30, 2018 at 05:59 AM
About 4 hours but i did it!
Code for the actual main object:
private void OnTriggerEnter(Collider other)
{
transform.Find("Particles").GetComponent<DeleteAfter>().AboutToDie();
Destroy(this.gameObject);
}
This will activate a function inside of the child (aka the particles aka 'Particles") and the function i named DeleteAfter
This is code inside the particles:
private void Start()
{
StartCoroutine(Something());
}
public void AboutToDie()
{
transform.parent = null;
GetComponent<ParticleSystem>().emissionRate = 0;
transform.localScale = new Vector3(1, 1, 1);
}
IEnumerator Something()
{
yield return new WaitForSeconds(3.0f);
Destroy(this.gameObject);
}
This waits 3 seconds to fully make sure that particles are done adjust to your needs and tada!
Answer by Asdcxz01 · Jul 30, 2020 at 02:51 PM
This worked great for me, I just had to remove transform.localScale = new Vector3(1, 1, 1); in my case ty
Your answer
Follow this Question
Related Questions
Particle System Instantiate wrong transform, position on Rig Builder / ragdoll conflict 0 Answers
Particles syncing on the Unity Network 4 Answers
Particles not showing 0 Answers
How to ensure particles draw? 1 Answer
Particles on Water 0 Answers