Finding and deleting objects

Hello
I’m making mapeditor for my game, so first thing you have to assign how big ground plane you want to have on your map,

in this example I have made ground with 1x1 size:

680983--24466--$nest1.png

Now I want to change size of ground to 5x6 so I get this:

680983--24465--$nest2.png

but the problem is what this old block still exists:

680983--24464--$nest3.png

so I have to make deleting objects tagged with “groundchunk” before the new chunks are made.
How to make code that will do something like:
Pick all objects in scene tagged with “groundchunk” and destroy them

this “picking” is the problem, I have never used something similar before so I really don’t know how to do it

this is the code for “OK” button on window where you enter new values of ground size:

if (GUI.Button(new Rect(Screen.width/2 +5, 200, 90, 20), "Ok"))
{
	SizeX = SizeXint;   [COLOR="seagreen"]//sets number of chunks on x-direction[/COLOR]
	SizeZ = SizeZint;   [COLOR="seagreen"]//sets number of chunks on z-direction[/COLOR]
	MapSize = false;   [COLOR="seagreen"]//closes window[/COLOR]
	Groundbuild();       [COLOR="seagreen"]//calls part of code for creating recently assigned sizes [/COLOR]
}

and this is “Groundbuild();” part which creates and align new set of ground chunks

void Groundbuild ()
{
	for (int i = Mathf.FloorToInt(SizeX * SizeZ); i>0; i--)
	{
		float xi = -1*(SizeX-1)*3/2 + (i - Mathf.FloorToInt((i-1)/SizeX)*SizeX -1) * 3;
		float zi = (SizeZ-1) * 3/2 - 3 * Mathf.FloorToInt((i-1)/SizeX);
		Instantiate ( Groundchunk, new Vector3(xi, 0, zi), Quaternion.identity);
	}
}
void ClearGroundTiles()
{
	GameObject[] groundTiles = GameObject.FindGameObjectsWithTag("groundchunk");
	for (int i = 0; i < groundTiles.Length; i++)
	{
		Destroy(groundTiles[i]);
	}
}

ty it’s working :slight_smile: