- Home /
Explosion prefab spawns only the first time in my published app, but spawns on every collision inside Unity Game mode.
I need an explosion prefab to spawn everytime it collides with the object tagged as 'Blast'. When I play it in the Game mode in Unity, it does indeed spawn each time it collides, but when I publish the package, and install the .apk on my device, it only spawns the first time it collides with the Blast object, and then, never again. Why would this difference happen ? Here is the code to spawn the explosion:
public GameObject deathExplosion;
void OnTriggerEnter2D(Collider2D blastCollisionCheck)
{
if (blastCollisionCheck != null) {
if (blastCollisionCheck.gameObject.tag == "Blast") {
Instantiate (deathExplosion, transform.position, transform.rotation);
Invoke ("Die", 1f);
}
}
}
void Die ()
{
Destroy (deathExplosion);
}
Answer by T27M · May 23, 2014 at 10:30 PM
Try this instead.
public GameObject deathExplosion;
void OnTriggerEnter2D (Collider2D blastCollisionCheck)
{
if (blastCollisionCheck != null) {
if (blastCollisionCheck.gameObject.tag == "Blast") {
GameObject explosion = Instantiate (deathExplosion, transform.position, transform.rotation) as GameObject;
Destroy (explosion, 1.0f);
}
}
}
Oh, I'll let this be a personal punch in the face coding primer for me. Thanks yet again @T27$$anonymous$$ .
Your answer
Follow this Question
Related Questions
How to Use Object Pooling? Is my Script Wrong? 0 Answers
Unity Crashes When Spawning Prefab 2 Answers
Spawning explosions and detecting objects in range 1 Answer
Make a object spawn 1 Answer
Exploding Mine Prefab not disabeling mesh renderer... 1 Answer