TIme -Bomb exploding issue
Hello everyone, i ve created an script for Time -bomb, which explodes after 3 seconds of countdown, it uses physics.overlapsphere to find collider colliding with it if there is a collider with rigidbody nearby it explodes and push the object away to some distance.
Problem iam having is that my game uses object pooling therefore it instantiate 3 bomb from which my player uses the bomb, so when 1st bomb works fine but 2nd one always do nothing , 3rd one is fine too but after 3 times of summon it stop working , following is the script , if anyone could help will be great, thanks void Explode() { print("step 1,2"); Instantiate(effect, transform.position, transform.rotation); Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
foreach (Collider nearbyCollider in colliders)
{
Rigidbody rb;
rb = nearbyCollider.GetComponent<Rigidbody>();
if (rb != null && !hasExploded)
{
rb.AddExplosionForce(explosionForce, transform.position, radius);
}
}
gameObject.SetActive(false);
print (gameObject);
// Destroy(gameObject);
}
Your answer
Follow this Question
Related Questions
Cannot destroy the SphereCollider on Instantiated Objects 1 Answer
Destroy instatiate object on trigger enter / collision,destroy instantiate prefab on trigger enter 0 Answers
My code is instantiating many prefabs, i only want one. 1 Answer
IsTouching() not working right after Colliders2D movement/instanciation 0 Answers