I noticed that the accepted answer is actually erroneous.
When using the Instantiate function of the MonoBehaviour class , we must indicate the type of what we are creating. I highly recommend reading the Create API Link .
To create a prefix as a GameObject
GameObject g = Instantiate(prefab) as GameObject;
To create a prefix as a Transform and provide a position in three-dimensional space.
Transform t = Instantiate(prefab, new Vector3(1,10,11), new Quaternion(1,10,11,100));
Destroy a component, which means that you can destroy scripts attached to gameObjects, as well as hard devices and other components.
Destroy(g);
or
Destroy(t.gameObject)
user2085599
source share