How would you spawn a prefab after the clone was destroyed in its place. When the asteroid hits Jupiter I would like the have a explosion effect after the collision. Here's my script.
using UnityEngine;
using System.Collections;
public class CollisionDetecter : MonoBehaviour {
public GameObject explosion;
void OnTriggerEnter(Collider asteroid) {
var spawnSpot = asteroid.transform.localPosition;
Destroy(asteroid.gameObject);
print ("destroyed " + asteroid + " " + asteroid.transform.localPosition + spawnSpot);
GameObject newObj = Instantiate(explosion, spawnSpot, Quaternion.identity) as GameObject;
newObj.transform.parent=transform;
newObj.tag = "Clone";
}
}
Currently the Explosions spawns somewhere else, which is way off. I tried to get the position of the asteroid, I also put explosion inside the sphere, still the same.
Here is my Hierarchy. The explosion is position 6 inside sphere. Maybe its something easy like asteroid.transform=transform, like with the parenting.
![alt text][1]
[1]: /storage/temp/16164-h.png
↧