- Home /
Particle System Start and Stop GetKeyDown/Up Not Working
I wrote a script that is supposed to start the particle system when you push the w key down and to stop it when you pull it up. I keep getting these errors:
Assets/Splash.js(6,32): BCE0020: An instance of type 'UnityEngine.ParticleSystem' is required to access non static member 'Play'.
Assets/Splash.js(12,32): BCE0020: An instance of type 'UnityEngine.ParticleSystem' is required to access non static member 'Stop'.
Here is the script:
function Update ()
{
if (Input.GetKeyDown ("w"))
{
ParticleSystem.Play;
}
{
if (Input.GetKeyUp ("w"))
{
yield WaitForSeconds (1);
ParticleSystem.Stop;
}
}
}
Answer by robertbu · Dec 28, 2013 at 10:19 PM
You want the instance of the particle system attached to this game object, not the ParticleSystem class. So use a small 'p'. And Play and Stop are functions, so you need the '()' after the function name:
particleSystem.Play();
Note this is a shortcut for:
gameObject.GetComponent(ParticleSystem).Play();
See the reference entry for GameObject for the things that have shortcuts.
Your answer
Follow this Question
Related Questions
How to create 3D particle effect? 1 Answer
Particle system drifting to a dynamic point 0 Answers
How to emit particles in one direction only? 1 Answer
2d particle system with custom sprite shape 1 Answer
Particle Playback Error in 5.4 0 Answers