Hi all. Got an issue with a class within a class not inheriting a value defined in the parent class. So far I have worked out that the DataMap class does not inherit the value ‘mapSize’ and thus the terrainTable array is initialised at size 0,0. It was working at one point; I don’t know if I changed anything or it broke on its own - most likely the former. Any help is greatly appreciated!
public class TileData : MonoBehaviour {
// attributes
private Vector2 mapSize = new Vector2();
private int tileRes;
DataMap dataMap;
public enum terrainTypes {
dirt = 0
}
class DataMap : TileData { // class holds a series of arrays that of metadata for all the tiles
public int[,] terrainTable;
public DataMap(){ // constructor : error, not inheriting!
terrainTable = new int[(int)mapSize.x,(int)mapSize.y]; // value of mapSize seems to not be inherited
Debug.Log("Data map made!");
}
}
// methods
public void OnSubmitClicked () {
Debug.Log("Submit Clicked!");
mapSize.x = int.Parse (xInput.text);
mapSize.y = int.Parse (yInput.text);
if (mapSize.x < 100 || mapSize.y < 100 ) {
ErrorReport("Out of Range");
} else {
Debug.Log ("Tile resolution is " + tileRes);
dataMap = new DataMap();
MakeAllTiles();
}
}
void MakeAllTiles(){ // makes all the tiles to the default value of dirt
Debug.Log ("The map dimensions are: " + mapSize); Debug.Log (dataMap.terrainTable.Length + " tiles to be generated"); // returns "0 tiles to be generated"
for (int x = 0; x < (int)mapSize.x; x++) {
for (int y = 0; y < (int)mapSize.y; y++) {
dataMap.terrainTable[x,y] = (int)terrainTypes.dirt;
}
}
}
}