private void GenerateResource(int y, int x) { float change = Random.Range(0, 1000); float currentChange = 0; foreach (var resourceData in resourcesData) { bool canPlaceOnTile = false; foreach (var tile in resourceData.placedOn) { if (tile == mapTypes[y, x]) { canPlaceOnTile = true; break; } } if (canPlaceOnTile) { if (change < resourceData.chance * 10 + currentChange) { resourceSystem.SpawnResource(new Vector3(x - (int)mapSize / 2, y - (int)mapSize / 2, 0), resourceData.tileVariants[Random.Range(0, resourceData.tileVariants.Length)]); return; } else { currentChange += resourceData.chance * 10; } } } }
// Start is called before the first frame update void Start() { resourceSystem.SpawnResource(treePosition, tree); resourceSystem.SpawnResource(rockPosition, rock); }