Search Unity

Enable the emission of a cloned particle system

Discussion in 'Scripting' started by herbie, Feb 6, 2013.

  1. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Hi,

    In my game I have a cannon that shoots balls.
    When the firebutton is hit, a clone of a ball (game object) is fired.
    When the firebutton is hit for the second time, a new clone is fired and the old clone is destroyed.

    I have a particle system for some smoke effects when the old clone is destroyed. Something like this:

    Code (csharp):
    1. particlesystem.enableEmission = true;
    2. yield WaitForSeconds(1.0);
    3. Destroy(GameObject.Find("ball(Clone)"));
    4. particlesystem.enableEmission = false;
    That all works fine, but...
    Of course the smoke effect must be at the position of the old clone that will be destroyed but it is at the position of the original ball.
    How can I have the particle system at the position of the clone?

    Actually, the particle system is also cloned, just as the ball. But how can I enable the emission from this cloned particle system?
    I only can enable the emission of the original particle system.
     
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    What function are you using the code in?

    If you have you cannon ball explode OnCollision or OnTriggerEnter then you can just Instantiate the smoke at the balls position and destroy the cannon ball all at the same time. On the particle system there is an option to destroy a few seconds after it's Instantiated.
     
    Last edited: Feb 6, 2013
  3. herbie

    herbie

    Joined:
    Feb 11, 2012
    Posts:
    237
    Thanks for reply.

    I don't use OnCollision or OnTriggerEnter because the cannon ball itselves does not explode. It's just as a steel ball that destroys everything on his way until it stops. If you use OnCollision or OnTriggerEnter it could be that the ball is destroyed while it is still moving.