swap objects with instantiate

hi

im still having trouble with swapping my objects.

im using this code to spawn a new 3d object(the spawning works with a prefab)

var pos : Rect;
var prefab : Transform;

function OnGUI()
{
   if (GUI.RepeatButton(pos, "Bodyconditionscore 2"))
   {
      var newObj = Instantiate(objPrefab, oldObj.transform.position , oldObj.transform.rotation); 
      newObj.transform.parent = oldObj.transform.parent;
   }
}

now i want to destroy my old 3dobject. The new 3dobject needs to be spawned at the same spot as the old 3d object was.(just like a swap)

The scripts from the old 3d obj needs te be copied to the new 3d object.

I asked some people about this on the holy internet but i cant get this instantiate working. could someone help me with this. im not a pro @ javascript or scripting. but i know a little bit

Any reason you can't just spawn two objects, have them share a parent that moves around, and just enable one/disable the other when you need them to swap?

The scripts are instantiated with the new prefab. I think you mean the variables that go with that script (the 'settings')?? If so, you should assign them across maybe something like this:

newObj.GetComponent(myScript).someSetting = oldObj.GetComponent(myScript).someSetting;
newObj.GetComponent(myScript2).someThing = oldObj.GetComponent(myScript2).someThing;

and then destroy the old object (or at least deactivate it)