Search Unity

ParticleEmitter help

Discussion in 'Scripting' started by Thunder0ne, Mar 28, 2009.

  1. Thunder0ne

    Thunder0ne

    Joined:
    Mar 8, 2009
    Posts:
    23
    I have attached two particle emitters to a bone of a gameobject. I want to enable or disable them upon predefined events having them turned off on start.
    Please find here my initialisation function.
    Code (csharp):
    1.  
    2. function Start () {
    3.    
    4.     var _particles : Component[] = GetComponentsInChildren(ParticleEmitter);
    5.    
    6.     for (var p : ParticleEmitter in _particles)
    7.     {
    8.         p.emit = false;
    9.     }
    10.    
    11.     while(true){
    12.         for (var p : ParticleEmitter in _particles)
    13.         {
    14.             if(partEmit){
    15.                 p.emit = true;
    16.             }
    17.             else{
    18.                 p.emit = false;
    19.             }
    20.         }
    21.         yield;
    22.     }
    23.    
    24. }
    25.  
    The error that I get states that the particles have been destroyed and therefore I can no longer access them.

    Could somebody kindly suggest the best practice to achieve this?

    Many thanks.