I’m trying to instantiate a prefab in a grid, and at certain coordinates in the grid I want to use a different prefab. For example I could generate the grid, but at 7,9 I could use the GameObject GrassHex instead of WaterHex.
The idea is that I can create a variable that randomly generates those coordinates, and then I can create a radius around that point. All objects in the grid within that radius will use a different prefab. This will create a “landmass” of GrassHex objects in the grid. Right now I have this script (this isn’t the whole thing, just the instantiate part), and it generates the grid just fine, but it only uses one prefab.
WaterHex is the main hex prefab
gridHeightInHexes and gridWidthInHexes are public variables defined in the inspector (later on defined in game)
How can I define which points on the grid use a particular prefab?
void createGrid()
{
GameObject hexGridGO = new GameObject("HexGrid");
for (float y = 0; y < gridHeightInHexes; y++)
{
for (float x = 0; x < gridWidthInHexes; x++)
{
GameObject hex = (GameObject)Instantiate(WaterHex);
//Current position in grid
Vector2 gridPos = new Vector2(x, y);
hex.transform.position = calcWorldCoord(gridPos);
hex.transform.parent = hexGridGO.transform;
}
}
}
Here is an example of what I get now, and here is a basic example of what I want to get.