How to delete a Variable in a script in game

I have 3 blocks. I have a script where when I look at a block I want it to delete the other 2 blocks. However these two blocks are variables in my script so when they are deleted in game the script is still trying to look for them and obviously they are not there any more so the game crashes. How can I make it so as well as deleting the 2 other blocks it removes the variables from the script. I have this script on all three blocks so which ever one I look at the other two are deleted. Here’s my script:

var Girl : GameObject;
var spawnPoint : Transform;
var Block : GameObject;
var Block2 : GameObject;

function OnBecameVisible(){
     var clone;
    clone = Instantiate(Girl, spawnPoint.position, spawnPoint.rotation);
   Destroy(Block);
   Destroy(Block2);
}

For each Block the variables Block and Block 2 are the other two blocks, any help would be great! Thanks.

You could check if your gameobject is destroyed or not, and if it’s not you: destroy it. You can’t actually delete a variable in the script, but you can check if it’s “empty” or not. If you want to “track” objects, you could use an array or list and when you destroy an object you also remove that gameobject from the list. Then you somehow have a list of active and running gameobjects in the scene.

var Girl : GameObject;
var spawnPoint : Transform;
var Block : GameObject;
var Block2 : GameObject;

function OnBecameVisible(){
    var clone;
    clone = Instantiate(Girl, spawnPoint.position, spawnPoint.rotation);

    if(Block != null) // check if Block isn't destroyed
        Destroy(Block);

    if(Block2 != null) // check if Block2 isn't destroyed
        Destroy(Block2);
}