Particle System not playing within If Statement

Hello.

I am trying to get a water particle system to come out of a faucet when I turn one of the handles (used with a hinge joint).

I check for the angle of the faucet, and successfully output the correct message to the console, so I know the if statement if working on it’s own, however, “water.Play()” does not seem to start the particle animation.

Just for the record, the faucet handles are not children of the faucet object, but the water particle system is.
Also, I tried unchecking “looping” for the particle system, which did not fix it.

As commented out in my code below, I also tried “water.enableEmission = true/false”, which also did not work.

Should I be using another function to play the system, such as “instantiate”?

Thank you, and here is the simple code I am using:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FaucetHandle : MonoBehaviour
{

    public GameObject handle;
    public ParticleSystem water;

    void Update()
    {
        if(handle.transform.localRotation.eulerAngles.y > 190)
        {
            water.Play();
            //water.enableEmission = true;
            Debug.Log("Water playing. Rotation: " + handle.transform.localRotation.eulerAngles.y);
        }
        else
        {
            water.Stop();
            //water.enableEmission = false;
            Debug.Log("Water stopped. Rotation: " + handle.transform.localRotation.eulerAngles.y);
        }
    }
}

Normally you’d want to call Play() once to start it playing. You’re calling it over and over every frame. I haven’t tried that, so not sure if that causes it to restart each time.

1 Like

Ah, true. Is there a way to check if the water is playing? Such as "if (water.Play() == true) {} "?

maybe this? not sure as i havent tested it!

2 Likes

Awesome, got it working by just checking if the water.isPlaying.

1 Like