- Home /
Question by
Coffeeluva · Jun 19, 2016 at 08:30 PM ·
errorinstantiatetransform.positiontransform.rotation
I'm trying to Instantiate the collided object.
Hi I have a cube and I have a sphere. When the cube collides with the sphere, the cube will be destroyed, then a clone of the sphere will be in the same position and rotation of the destroyed cube. What I'm trying to do is, If an object that has the tag 'Morph' collides with the object that has the script, then the object with script gets destroyed and replaced with the 'Morph' object. I get the error "No appropriate version of 'UnityEngine.Object.Instantiate' was found. What am I doing wrong?
function OnCollisionEnter (morph: Collision)
{
if(morph.gameObject.tag == "Morph")
{
Instantiate(morph, gameObject.transform.position, gameObject.transform.rotation);
Destroy(gameObject);
}
}
Comment
Best Answer
Answer by TBruce · Jun 19, 2016 at 09:03 PM
Change
Instantiate(morph, gameObject.transform.position, gameObject.transform.rotation);
to
Instantiate(morph.gameObject, gameObject.transform.position, gameObject.transform.rotation);