Deleting instantiated prefabs clones?

I need to delete an instated gameObjects clone once I instate it again, for example if a person were to place a block, the next time that person would place that same block the original would become destroyed. How would one do this?? what is the theory behind the code?

I’ve tried using static variables and some very complex methods to not much avail.

When you instantiate the first block give it a a name. Then when you instantiate the second block, check if that name exists, if so delete it and assign the second block to the name.

function PlaceBlock(){

var clone : GameObject;
if(clone!= null){
Destroy(clone);
clone = instantiate.........

}
else
clone = instantiate.........
}

this will give you errors but you get the idea right?

Anxo’s answer is one way to do it. Here is another.

You can give the box a tag, like, “box”. Then you create a new script and place it on the box that looks for boxes at the beginning and destroys it.

Like this.

function Awake(){
     var oldBox : GameObject = GameObject.FindWithTag("box");
     if(oldBox)
     {
          Destroy(oldBox.gameObject);
     }


} 

Then every time a new box comes in the scene, it will look for the old box and if there is one it destroys it.