Code: Select all
public void SpawnResources()
{
for (int x = 0; x < roomWidth; x++)
{
for (int y = 0; y < roomHeight; y++)
{
if (grid[x, y] == gridSpace.floor &&
Random.value < chanceToSpawnResource)
{
GameObject resource = Resources[Random.Range(0, Resources.Length)];
Spawn(x, y, resource);
}
}
}
GenIsDone = true;
}
Code: Select all
void Spawn(float x, float y, GameObject toSpawn)
{
//find the position to spawn
Vector2 offset = roomSizeWorldUnits / 2.0f;
Vector2 spawnPos = new Vector2(x, y) * worldUnitsInOneGridCell - offset;
//spawn object
var obj = Instantiate(toSpawn, spawnPos, Quaternion.identity);
obj.transform.parent = GenParent.parent;
}
So what would be the best way to save my map generation ?