- Home /
Turning on and off Particle effects
Hi. I'm trying to do something that IDK if its possible. I'm working on a 3d space shooter and I have explosion particle effects. I followed some youtube tutorials as I'm no expert with particle effects and something that I found out is that everybody creates a prefab and instantiates a gameObject Explosion when needed and when the effect is done, they destroy that gameObject Explosion.
I tried to instantiate them on start and have them inactive, so basically have a pool to pull from and turn on every time I need one. When I need one I turn it on, I see the particle effect and turn off the effect and it works ONLY the first time. When I turn on a gameObject Explosion that I already used, its like the particle effect is already spent. Is there a way in which I can reset the particle effect so I can use it again?
If there is a script for that or an explanation, try to keep it in C# please as that is the language I'm using, but if you already have it in javascript, feel free to post as well.
Thank you for your time.
@rajavamsidhar_gvs sorry for the late reply (i thought i already had replied). thank you, that was exactly what i was looking for.
its ok.if it works vote up and accept as answer
Answer by rajavamsidhar_gvs · Feb 23, 2016 at 10:58 AM
hi..you can try this.i didnt tested.once check it and let me know result.
public GameObject particlePrefab;//drop your particle effect prefab here
public GameObject bulletout;//drop your bullet out object
void Start()
{
particlePrefab.setActive(false);
}
void Update()
{
if(input.GetMouseDown(0))
{
GameObject Bullet=Instantiate(particlePrafab,bulletout.transform.position,bulletout.transform.rotation)as GameObject;
Bullet.setActive(true);
Bullet.GetComponent<ParticleSystem>().Play();
}
}