0
\$\begingroup\$

I have child object with ParticleSystem component. I want to have particles disabled until I press button.

I unchecked child object to make it disabled but when I press play it enables automatically(with no scripts attached). Then I made this script below (with .SetActive(false) part only) and it worked.

But then I needed to activate it somehow, which I did, but now when I press play, object is automatically enabled/ activated again.

Is there another way of doing this because I need it haha.

var particle1: GameObject;
var particle2: GameObject;
var particle3: GameObject;

public var triggered : boolean = false;

function OnTriggerEnter() { triggered= true; }
function OnTriggerExit()  { triggered= false;}

function Start()
{
    particle1.SetActive(false);
    particle2.SetActive(false);
    particle3.SetActive(false);
}

function Update()
{
    if (triggered && Input.GetKeyDown(KeyCode.JoystickButton1))
        particle1.SetActive(true);
        particle2.SetActive(true);
        particle3.SetActive(true);
}
\$\endgroup\$
  • \$\begingroup\$ I don't know if it is intended, but in your Update() there is no brackets on the three following lines, which means that at each loop, particle2 and particle3's SetActive(true) will be called. \$\endgroup\$ – Alexandre Desbiens Aug 4 '14 at 14:40
  • \$\begingroup\$ Yeah, I want all three particles to run when object is activated \$\endgroup\$ – Samurai Fox Aug 4 '14 at 14:42
  • \$\begingroup\$ No, not in the Start function, in the Update one, with the Input.getKeyDown(...). The Update() function is called many times a second, so particle2 and particle3 will be enabled again on each loop. \$\endgroup\$ – Alexandre Desbiens Aug 4 '14 at 14:44
  • \$\begingroup\$ it was the curly brackets in Update() func. that were the problem...thanks anyways \$\endgroup\$ – Samurai Fox Aug 4 '14 at 14:45
1
\$\begingroup\$

It might be related to your Update function:

function Update()
{
    if (triggered && Input.GetKeyDown(KeyCode.JoystickButton1))
        particle1.SetActive(true);
        particle2.SetActive(true);
        particle3.SetActive(true);
}

Having no brackets, only particle1.setActive(true) is in the condition. The other two will be called on each Update() loop. Try adding brackets and see if the problem persists:

function Update()
{
    if (triggered && Input.GetKeyDown(KeyCode.JoystickButton1))
    {
        particle1.SetActive(true);
        particle2.SetActive(true);
        particle3.SetActive(true);
    }
}
\$\endgroup\$
  • \$\begingroup\$ yap...that was it...thanks I'm actually kind of ashamed I didn't think of that haha \$\endgroup\$ – Samurai Fox Aug 4 '14 at 14:44
  • \$\begingroup\$ No problem. Small errors like this happens even to the best programmers (i'm talking about you, semicolon). \$\endgroup\$ – Alexandre Desbiens Aug 4 '14 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.