Search Unity

Particle system activation issues.

Discussion in 'Scripting' started by m1interactive, Jul 20, 2007.

  1. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    I'm a Unity and scripting newbie and I'm stuck. I'm trying to create a fire extinguisher effect when I hold down the fire button, and when released, it stops.

    I don't think I need it instantiated, as it's just on or off, not duplicating itself. Using the CreateParticleSystem.js as an example, I deleted the parts of the script to tell the particles where and how to emit from on a surface.

    function Update () {
    // Did the user press the mouse button?
    if (Input.GetMouseButtonDown (0)) {

    Instantiate (particleSystem);
    }

    }


    But this doesn't work, I just get an error-is there an easy way to turn the particles on/off per mouse button activation that I missed?

    My goal is to run around using my fire extinguisher to extinguish objects that are on fire. Any other tips or hints??
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Try this on your particle system:

    Code (csharp):
    1. function Update ()
    2. {
    3.      if (Input.GetMouseButtonDown (0))
    4.           particleEmitter.emit = true;
    5.  
    6.      else if (Input.GetMouseButtonUp (0))
    7.             particleEmitter.emit = false;
    8. }
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    And in case it's not obvious, you'll need to create the particle system yourself ahead of time, and then attach this script to it. Make sure that the ParticleEmitter's "emit" field is unchecked in the inspector, otherwise your fire extinguisher will be spraying when the game starts.
     
  4. m1interactive

    m1interactive

    Joined:
    May 4, 2007
    Posts:
    19
    Hi guys, thanks!! This rules. Now it totally makes sense, I just need to get more familiar with scripting and js.
    Much appreciated!!
    Brian