script gets this error: (6,20): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, System.Object)' was found.

im making a car game were the player car collides with an enemy car and destroys it. in level 1 it’ll have 2 cars that can be destroyed. when there are no enemy cars remaining, which will load a new level.

public var explosionPrefab : GameObject;

var beep : AudioClip;

function OnCollisionEnter(col: Collision){

if (col.gameObject.tag == “Player”){

Instantiate(explosionPrefab,col.gameObject.transform);//trigger explosion

Destroy(col.gameObject);

audio.PlayOneShot(beep);

}

}

This is the error:

(6,20): BCE0023: No appropriate version of ‘UnityEngine.Object.Instantiate’ for the argument list ‘(UnityEngine.Transform, System.Object)’ was found.

I dont know whats wrong because it has never happened before that i got this error, ive had a common add a “;” in this or that line. what is wrong what this script?

That’s not how Instantiate works.

http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

You need to change the 2nd parameter to col.gameObject.transform.position and add a variable for rotation (probably either col.gameObject.transform.rotation or Quaternion.identity depending on what you want)

var explosionPrefab : Transform;
var beep : AudioClip;

function OnCollisionEnter(col: Collision){

if(col.gameObject.tag == “Player”){

Instantiate(explosionPrefab,col.gameObject,transform.rotation);

Destroy(col.gameObject);

audio.PlayOneShot(beep);

}

}