- Home /
make explosion work
public var explosionPrefab : Transform;
var beep : AudioClip;
function OnCollisionEnter(col: Collision){
if (col.gameObject.tag == "Player"){
Destroy(col.gameObject);
audio.PlayOneShot(beep);
}
}
how can i make the "explosionPrefab" work after the object is destroyed after collision
Answer by Dreamer · Jun 03, 2011 at 04:54 AM
First you should declare explosionPrefab as gameobject, and set the particle to be "One shot"
public var explosionPrefab : GameObject;
var beep : AudioClip;
function OnCollisionEnter(col: Collision){
if (col.gameObject.tag == "Player"){
Instantiate(explosionPrefab,col.gameObject.transform.position);//trigger explosion
Destroy(col.gameObject);
audio.PlayOneShot(beep);
}
}
(6,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, System.Object)' was found.
Answer by Eli-Davis · Jun 03, 2011 at 04:55 AM
var explosionPrefab:Transform;
var beep : AudioClip;
function OnCollisionEnter(col: Collision){
if (col.gameObject.tag == "Player"){
Instantiate(explosionPrefab,transform.position, transform.rotation);
audio.PlayOneShot(beep);
Destroy(col.gameObject);
}
}
(6,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, System.Object)' was found.
Alright, try this code exacly, I updated my awnser, if it still doesn't work. sorry
Your answer
![](https://koobas.hobune.stream/wayback/20220612094538im_/https://answers.unity.com/themes/thub/images/avi.jpg)