简体   繁体   中英

unity3d turn on off particle system

i am trying to turn on and off a particle system i created.
I attached it to a prefab.

The code I am using is as follows

public ParticleSystem waterGun;

void Update () {
    if(Input.GetKey(KeyCode.W)){
        waterGun.enableEmission = true;
    }else if(Input.GetKeyUp(KeyCode.W)){
        waterGun.enableEmission = false;
    }
}

I want the particle system to play in front of the fps when a key is held down and stop playing when it is pressed.

Try using:

waterGun.Play();

and

waterGun.Stop();

And also, your logic is inverted, like Joetjah said.

You say that the "waterGun prefab is given to it" but you should be assigning an instance of a particle system in the scene to waterGun, not the prefab. A prefab doesn't exist in the scene.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM