Bool Value reversed

Hey all,

Got a situation here, wondering if I can get some help. Have a game object emitting particles based on a bool. It should “Play()” when value is true. Problem is, it is doing just the opposite, plays when value is false, and stops when value is true.

public class Flamethrower : MonoBehaviour
{
	public float lvl, damage;
	public bool fire;
	public ParticleSystem flame;


	void Start ()
	{

	}
	
	void OnParticleCollision (GameObject other)
	{
		Armor armor = other.GetComponent<Armor> ();
		if (armor != null)
			armor.TakeDamage (damage);
	}
	void Update ()
	{
		Debug.Log (fire);
		
		if (fire == true) {
			flame.Play ();
		}
	}
}

even more weird is that i am not calling a Stop(), but it stops on its own as soon as the value is true. What is going on here?

Hello, you are calling Play() every frame when fire == true , this causes it restart every frame. this is your problem.

Problem with your script is that you are calling the Play method even when the particle effect is not finished playing.Which makes the particle effect to play it’s first frame on every frame.You can avoid this by using one more condition check as below

if (fire == true && !flame.isPlaying) {
			flame.Play ();
		}