Swap objects

hi,

i got an game object with components scripts attached to it. if the player clicks on a gui button the engine needs to destroy the current object and load a new object with the same components, scripts, settings, position etc. (like a swap of objects)

this is what i got

var pos : Rect;
var pos2 : Rect;


function OnGUI()
{
  if (GUI.Button(pos, " Swap "))
  {
   Destroy (gameObject);


player = new GameObject ("the new gameobject");
player.AddComponent ("Rigidbody");
player.AddComponent ("SphereCollider");
player.AddComponent ("Mesh Renderer");
player.AddComponent ("Drag NRotate 2");
  }

some guy on answer.unity said i need to use instantiate?

im new to scripting in unity.

greetz

Some guy was right :slight_smile: