- Home /
Editor script for automatic ground tile prefabs placement?
Hi, i want to be able to quickly construct the tiled ground from prefabs with sprite renderers(one for a tile sprite). Basically i just want to be able to spawn a grid of copies of the same prefab with varied dimentions, say - sand tile, 20 * 10 will create those 20 rows of 10 prefabs in the Scene, aligned into a grid.
Maybe somebody knows a free plugin for this? or even have written it earlier?
Answer by ShadyProductions · Nov 30, 2017 at 01:15 PM
Not very hard to write. Here's a quick method. You might want to change y with z if needed.
public void MakeGrid(GameObject tile, int mapsizeX, int mapsizeY) {
for (int x=0; x < mapsizeX; x++) {
for (int y=0; y < mapSizeY; y++) {
Instantiate(tile, new Vector3(x, y, 0), Quaternion.identity);
}
}
}
Your answer
Follow this Question
Related Questions
Keeping state that cannot be serialized between play mode for EditorWindow 1 Answer
Access Monobehavior Instance from Static Function of Editor Script 1 Answer
Is it possible to have editor-only native plugins? 0 Answers
Editor scripting - How to show the Assets menu as a context menu 1 Answer
Cannot close/unload a scene that is open in editor during playmode (using C# code)? 3 Answers