- Home /
How do you access a Shuriken particle system through javascript?
Hey everyone. I'm still a bit new to Unity and scripting in general, and am having trouble figuring out to access a Shuriken particle system through javascript. Specifically I want to turn it on and off for a gunfire effect. I've tried looking at the scripting reference, as well as various answers and forum posts and came up with this script here which is placed on the empty game object that also contains the particle system component.
private var myParticles : ParticleSystem;
function start ()
{
myParticles = gameObject.GetComponent(ParticleSystem);
myParticles.enableEmission = false;
}
As far as I know this should work, however the particle effect continues to emit when I play the scene. I get no error either. I feel like I'm missing something.
As I mentioned I checked out a few posts in an attempt to find the answer myself, including these:
http://answers.unity3d.com/questions/235724/turn-on-off-shuriken-particle-system.html http://forum.unity3d.com/threads/118117-Starting-and-Stopping-Emitters-in-the-new-Shuriken-Particle-System
Those lead me to the code you see. Since I'm new I find it a little hard to decipher some of the information I find, and the scripting reference doesn't really give me enough context for me to know if I'm missing something basic. Any help would be appreciated. Cheers!
Answer by wiivil-canevil · Apr 03, 2014 at 09:43 AM
Set the particle effect to 'one shot' in the particle effect inspector window. Deactivate the particle system and then activate it every time the person presses the fire button. Haven't used javascript in a while but just use an if statement.
if(buttonpress fire 1 == true) { activate the particle effect }
Your answer
Follow this Question
Related Questions
Remove wireframe on particle systems 3 Answers
Whats the best way to create a 'legacy' particle system? 1 Answer
Question on Max Particle Size 0 Answers
Rotation of particle system (Shuriken) 1 Answer
Shurkien particle system shadows 0 Answers