- Home /
 
Particle System On Key Press
I'm trying to add a particle effect when my player walks in my game, but I don't even know where to begin. Can anybody help me? It's a 2D game in case it matters.
Answer by cryingwolf85 · May 22, 2014 at 06:24 AM
Go to : GameObject > Create Other > Particle System
Under "Particle System" on the particles in the Inspector, un-tick "Play On Awake"
In your player script, reference the ParticleSystem at the top of the class:
 public ParticleSystem particles;
 
               Drag the particles in your Hierarchy view into the particles variable slot on the player script.
Where you check for movement in your player script, do something like the following:
     if(Input.GetKeyDown(KeyCode.A)){
         particles.Play();
     }
     
     if(Input.GetKeyUp(KeyCode.A)){
         particles.Stop();
     }
 
               Or if you are using GetAxis or GetAxisRaw:
     float axis = Input.GetAxis("Horizontal");
 
     if(axis < 0 || axis > 0 && !particles.isPlaying){
         particles.Play();
     }
     else if(particles.isPlaying){
         particles.Stop();
     }
 
               That should be enough to get you on the right track.
You can also use particles.Pause, particles.enableEmission = true/false, and particles.Emit.
Answer by Sisso · May 23, 2014 at 05:12 PM
Start from the beginning
http://docs.unity3d.com/Documentation/Manual/Input.html
http://docs.unity3d.com/Documentation/Manual/ParticleSystems.html
Your answer