Replace the instantiated object with another instantiated object

Hey guys just wanna know on how can i delete or destroy an already instantiated object inside my game with another instantiated object… The first instantiated object has different script with the one that will be replaced by the new instantiated object… can someone give me an example on how can i do that thing ?.. pseudo code, actual code or any answer that will give me an idea to do it will be very much appreciated… thank you :slight_smile:

If the only difference is the script, then it would be more efficient to just remove the old component and replace with the new component. For Javascript:

 Destroy(GetComponent(SomeComponent));
 gameObject.AddComponent(AnotherComponent);

If you really want to replace the whole gameObject with another prefab, it will be something like this (assumes the script to replace the object is on the object to be replaced):

 var go : GameObject = Instantiate(newPrefab, transform.position, transform.rotation);
 Destroy(gameObject);