I’m trying to set the parts of a chunk as children of the chunk prefab.
World.cs creates chunks from my Map prefab, and each Map prefab creates a grid from my Square prefab. But the squares can’t be made children of the Map. The error is:
gridPart.transform.parent = (GameObject) this;
Cannot convert type ‘Map’ to ‘UnityEngine.GameObject’
Here is the relevant code that causes the error.
(I can’t get the code to format correctly…sorry about that)
public virtual IEnumerator DrawMap(){ //creates the grid of terrain tiles according to WIDTH and HEIGHT
for (float i = transform.position.x; i < transform.position.x+width; i++) {
for (float j = transform.position.y; j < transform.position.y+height; j++){
Vector3 pos = new Vector3 (i, j, 0);
bool squareAtLocation = Square.SquareIsAtPosition(pos);
if(squareAtLocation){
yield return 0;
}
else{
GameObject gridPart = (GameObject) Instantiate(squarePrefab, new Vector3 (i, j, 0), Quaternion.identity);
gridPart.transform.parent= (GameObject) this;
}
}
}
yield return 0;
}