- Home /
[Closed] Cannot convert types?
I have been working on random generation of objects and I came across an error, like I always do, and I can't figure this one out. I have been trying to set certain parts of the heightmap, and this was just a test to see if it would work, but the types aren't converting like they should! it says that in the for loop it can't convert the Heightmap[x, y] to Heightmap[buildingPlacementX, buildingPlacementY] when it should be able to...
public void GenerateBuilding(Terrain buildingTerrain, GameObject building) {
TD = buildingTerrain.terrainData;
Heightmap = new float[TD.heightmapWidth, TD.heightmapHeight];
float buildingPlacementX = Random.Range(10f, TD.size.x - 10f);
float buildingPlacementZ = Random.Range(10f, TD.size.z - 10f);
int buildingPlacementY = (int)buildingTerrain.SampleHeight(new Vector3(buildingPlacementX, 0, buildingPlacementZ));
Instantiate(building, new Vector3(buildingPlacementX, buildingPlacementY, buildingPlacementZ), Quaternion.identity);
for (float x = 0f; x < (float)TD.heightmapWidth; x++) {
for (float y = 0f; y < (float)TD.heightmapHeight; y++) {
if (Heightmap[x, y] == Heightmap[buildingPlacementX, buildingPlacementZ]) {
Heightmap[x, y] = (float)buildingPlacementY;
}
}
}
TD.SetHeights(0, 0, Heightmap);
}
Typically if you have an error it is helpful for others to know the error as well if you want any hope in someone helping unless they pretty much know what you are doing.
BTW: why is there a [closed] in front of your title when the question isn't closed?
Your answer
Follow this Question
Related Questions
Convert a char to int / float 2 Answers
Positive to negative not working? 1 Answer
Timer - CS0029: Cannot implicitly convert type `float' to `bool' 1 Answer
Why aren't these numbers going down by 1. 1 Answer
Keep height at edge TerrainToolkit 0 Answers