x


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

more ▼

asked Apr 05 '12 at 12:39 PM

StevieMac gravatar image

StevieMac
0 4 4 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
    }          
}

}

more ▼

answered Apr 10 '12 at 12:59 PM

StevieMac gravatar image

StevieMac
0 4 4 5

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Nov 16 '12 at 05:13 AM

trooper gravatar image

trooper
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x638
x163

asked: Apr 05 '12 at 12:39 PM

Seen: 3282 times

Last Updated: Nov 16 '12 at 05:13 AM