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: Now I want to change size of ground to 5x6 so I get this: but the problem is what this old block still exists: 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: Code (csharp): 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 Code (csharp): 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); } }
Code (csharp): void ClearGroundTiles() { GameObject[] groundTiles = GameObject.FindGameObjectsWithTag("groundchunk"); for (int i = 0; i < groundTiles.Length; i++) { Destroy(groundTiles[i]); } }