- Home /
Turn On & Off Shuriken particle system?
Could someone please show me the java script to do this as I've been trying for 3 days now to find something that works.
This is what I have been working with so far I want it to work with one button to turn it on & off really but this is just for testing.
var particle : ParticleSystem;
function OnGUI () {
//background box
GUI.Box (Rect (0,160,100,150), "Weather");
if (GUI.Button (Rect(10,190,80,20), "Snow On"))
{
particleEmission.enabled = true;
}
else
if (GUI.Button (Rect(10,220,80,20), "Snow Off")){
particleEmission.enabled = false;
}
}
So the particle system is called Snow & is a Shuriken particle system (that I know of) which is Parented to an empty GameObject called Particles.
I really don't understand code that well so please explain it simply or just post the code. Thanks anyway guys/gals
Answer by StevieMac · Apr 10, 2012 at 12:59 PM
Here's the answer from a friend of mine. I hope it helps you guys too.
Put the script on this game object : Particle Systems Snow <------
function OnGUI () { //background box GUI.Box (Rect (0,160,100,150), "Weather");
var particleSystem : ParticleSystem;
particleSystem = gameObject.GetComponent(ParticleSystem);
if (particleSystem.enableEmission)
{
if (GUI.Button (Rect(10,190,80,20), "Snow Off"))
{
particleSystem.enableEmission = false;
}
}
else
{
if (GUI.Button (Rect(10,190,80,20), "Snow On"))
{
particleSystem.enableEmission = true;
}
}
}
Answer by trooper · Nov 16, 2012 at 05:13 AM
The above post is correct but if you don't have "Play On Awake" enabled you'll also need to call
particleSystem.Play();
During a start or awake function.