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);
            } 
        }

1 Answer

1

Change

Instantiate(morph, gameObject.transform.position, gameObject.transform.rotation);

to

Instantiate(morph.gameObject, gameObject.transform.position, gameObject.transform.rotation);

Thanks it worked!