- Home /
error when played in unity engine
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?
Answer by FLASHDENMARK · Jun 03, 2011 at 03:20 PM
public var explosionPrefab : GameObject;
var beep : AudioClip;
function OnCollisionEnter(col: Collision)
{
if (col.gameObject.tag == "Player")
{
Instantiate(explosionPrefab,col.gameObject.transform, transform.rotation);
//trigger explosion
Destroy(col.gameObject);
audio.PlayOneShot(beep);
}
}
A Instantiate function needs 3 variables. What to instantiate, where it should
Instantiate and what rotation the instantiated object has. You only gave it 2 variables.
Your answer
Follow this Question
Related Questions
How "include" the Raycast?! 1 Answer
Instantiate Problem 1 Answer
sound on button press error + its firing when space is pressed 1 Answer