Remove object based on its position alone

Language = Javascript

I have a number of terrain pieces tiled together.

At some point I want the Destroy them with some script.

But the terrain objects themselves are all clones.

All I need is something that allows me to grab / identify the object at an X and Z position that I already know.


Destroy ( get.gameObject(x,y,z) ) ;

I realise this code above doesn’t work… but it gets my point across. Can anyone help me with this? I’ve heard about the Sphere overlap thing but it might be more complicated then I can handle. Is there any simple command?

Perhaps I could name the terrain object with their locations in their name instead and destroy them that way?

try to make a dictionary to map the position of your objects (or create an xml)
If you create your tiles on the fly do something like this

Dictionary< Vector3, Gameobject > myMap;
void CreateTile()
    Gameobject myTileObj;
    //blah blah create and place tile and set it to the myTileObj
    //Supposing that 2 tiles will never have the same position then
    if( !myMap.Contains( myTileObj.transfor.position ) )
        myMap.add(Vector3, myTileObj);        

Vector3 GetTileByPosition( Vector3 position )
     if( myMap.Contains(position) )
         return myMap[position];

tell us later if this works or not