How to activate a particle effect on keypress?(my script is not working properly)

Hello,i would like to enable the emission of a particle effect for as long as i m pressing the key.I attached the script below to the particle system and i unchecked ‘‘Play on awake’’.Whenever i press Shift nothing is happening.If i check ‘‘Play on awake’’ the emission will start on its own and stop when i press shift.Once it has stopped,i can enable the emission by pressing Shift whenever i want.This way it is working as intended except of playing on awake,i don’t want it to play on awake.What am i doing wrong? :confused:

using UnityEngine;
using System.Collections;

public class Particlesonkeypres : MonoBehaviour {
    public ParticleSystem Particletest;
  
    void Update () {
        if(Input.GetKey(KeyCode.LeftShift)){
            Particletest.enableEmission = true;
        }else if(Input.GetKeyUp(KeyCode.LeftShift)){
            Particletest.enableEmission = false;
        }
    }
}
1 Like

If you have play on awake disabled, you probably need to call Play() on the particle system when you first turn it on.

3 Likes

hey,consider my question solved!Thanks a lot!

1 Like