- Home /
Particle system mouse click
I'm trying to get a simple particle flamethrower to work in Unity with a particle system and mouse click. I think the else statement is causing an issue. Nothing happens when I press the left trigger or take my finger off like I assume the code should.
On press (hold) start particle, then whenever I'm not, stop it?
#pragma strict
var flameThrower : ParticleSystem;
function Start ()
{
flameThrower.Stop();
GameObject.Find("FlameCollider").GetComponent(Collider).enabled = false;
}
function Update ()
{
if (Input.GetMouseButton(0))
{
flameThrower.Play();
GameObject.Find("FlameCollider").GetComponent(Collider).enabled = true;
Debug.Log("Play");
}
else
{
flameThrower.Stop();
GameObject.Find("FlameCollider").GetComponent(Collider).enabled = false;
Debug.Log("Stop");
}
}
I have amended my answer, let me know if it helps please :)
Answer by sacredgeometry · Aug 10, 2013 at 09:30 AM
EDIT:
After a little bit of testing I realised what was the issue. Instead of using stop and play you should probably be changing the emission rate. Try this. (obviously you may want to set the rate to a public variable)
if(Input.GetMouseButton(0))
{
flamethrower.emissionRate = 150.0f;
}
else {
flamethrower.emissionRate = 0.0f;
}
Cheers man, that worked a treat! Thanks for your time!
Your answer
![](https://koobas.hobune.stream/wayback/20220613111849im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating fire particle in code 1 Answer
Gun Firing help? 2 Answers
fire spell 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Particle following Emitter Problem 3 Answers