Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);
}
share|improve this question
    
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. – Alexandre Desbiens Aug 4 '14 at 14:40
    
Yeah, I want all three particles to run when object is activated – Samurai Fox Aug 4 '14 at 14:42
    
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. – Alexandre Desbiens Aug 4 '14 at 14:44
    
it was the curly brackets in Update() func. that were the problem...thanks anyways – Samurai Fox Aug 4 '14 at 14:45
up vote 1 down vote accepted

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);
    }
}
share|improve this answer
    
yap...that was it...thanks I'm actually kind of ashamed I didn't think of that haha – Samurai Fox Aug 4 '14 at 14:44
    
No problem. Small errors like this happens even to the best programmers (i'm talking about you, semicolon). – Alexandre Desbiens Aug 4 '14 at 14:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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