Search Unity

Detonator Explosion Pack and Pooling

Discussion in 'Scripting' started by YorkshirePudding, Apr 18, 2013.

  1. YorkshirePudding

    YorkshirePudding

    Joined:
    Apr 10, 2013
    Posts:
    18
    Hi All,

    I am using a simple pooling system from the asset store (Pooling Manager) which does what I ask it to nicely. However, I've been trying to get the Detonator Explosions to work with the pooling system. I have created a prefab with one of the explosions in and created a script that handles the timeout of an object and releases it back to the pool. I then set the timeout value on the detonator to zero and unchecked the explode on start.

    This all works fine, the explosions are generated in the world when needed then set inactive when they have finished and released back into the pool. However, I am unable to get the explosions to start, I tried calling the Explode method which did nothing, I then tried calling Reset, then Explode but still nothing.

    Does anybody have any ideas?
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Dunno if you still need help with this... by timeout value do you mean destroy time? I did it pretty much the same as you described and it works perfectly, quite fast too...

    First I turned off explode on start, set destroy time to 0, and left duration at 3.

    Here is my reset function

    Code (csharp):
    1.  
    2.     void Update()
    3.     {
    4.         for (int d=0;d< maxExplosionPool;d++)
    5.         {
    6.             if ( active[d] == true )
    7.             {
    8.                 explosionsTtl[d] += 1.0f * Time.deltaTime;  
    9.                
    10.                 if ( explosionsTtl[d] >= duration )
    11.                 {
    12.                     explosions[d].GetComponent<Detonator>().Reset();
    13.                     explosions[d].SetActive(false);
    14.                     explosionsTtl[d]=0.0f;
    15.                     active[d]=false;
    16.                 }
    17.             }      
    18.         }
    19.     }
    20.  
    Then I just set the explosion to active, set the position and called explode() on a bullet collision.

    Hope that helps
     
    Last edited: Sep 11, 2014