Search Unity

Working with Mesh Particle and Emitter

Discussion in 'Scripting' started by littlelingo, Aug 4, 2006.

  1. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    I was hoping to be able to turn on/off a particle emitter via the Emit property. In the GUI it looked to be a boolean so figured I could access it that way in code. After looking at the documentation this seems to not be the case or am I missing something? If this doesn't work is there a way someone could suggest?

    My code looks like this:

    Code (csharp):
    1.  
    2. if (! part.Emit){
    3.     part.particleEmitter.Emit = true;
    4. }
    5.  
    The error I am getting is:

    Expression cannot be assigned to.

    Thanks for the help!

    Regards,

    -- Clint
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    You want particleEmitter.emit (lower case)

    It looks like there is a bug in the Unity documentation for emit

    http://unity3d.com/Documentation/ScriptReference/ParticleEmitter.emit.html

    It directs you to the function Emit instead, maybe because the web server doesn't care about case, or something.

    Is that all of your script? If it is, you need to put a var at top named "part" and do that drag-and-drop maneuver we discussed in the other thread. Then if you refer to this var as ParticleEmitter, then you can just do part.emit instead of part.particleEmitter.emit. It's less typing, cleaner, and a teeny tiny bit faster.

    -Jon
     
  3. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Cool thanks for the info. Below is the entire script. Look okay?

    Code (csharp):
    1.  
    2. var showerEmitter : GameObject;
    3.  
    4. function OnMouseDown(){
    5.    
    6.     if (! showerEmitter.particleEmitter.emit){
    7.         showerEmitter.particleEmitter.emit = true;
    8.     }
    9.    
    10. }
    11.  
    12.  
    13. function OnMouseUp(){
    14.  
    15.     if (showerEmitter.particleEmitter.emit){
    16.         showerEmitter.particleEmitter.emit = false;
    17.     }
    18.  
    19. }
    20.  
    Regards,

    -- Clint
     
  4. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    BTW, should I write a bug about the documentation?

    Thansk for all the help!

    -- Clint
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Not necessary i did that myself after reading your post.