I have custom class Map
which contains 2 lists of custom classes Bricks
and Dangers
. Problem is that my code is not adding elements to that custom classes.
public class Map
{
public string mapName;
public List<Brick> bricks;
public List<Danger> dangers;
public Map()
{
bricks = new List<Brick>();
dangers = new List<Danger>();
}
}
public class Brick
{
public Vector2 Position;
}
public class Danger
{
public Vector2 Position;
}
private void CreateMap()
{
Map map = new Map();
map.mapName = "test";
map.bricks.Add(new Brick { Position = new Vector2(1, 1) });
map.bricks.Add(new Brick { Position = new Vector2(2, 1) });
map.bricks.Add(new Brick { Position = new Vector2(5, 1) });
map.bricks.Add(new Brick { Position = new Vector2(6, 1) });
map.bricks.Add(new Brick { Position = new Vector2(7, 1) });
map.dangers.Add(new Danger { Position = new Vector2(3, 1) });
map.dangers.Add(new Danger { Position = new Vector2(4, 1) });
Debug.Log(JsonUtility.ToJson(map));
AddMap(map);
}
As an output from Debug.Log
i get {"mapName:": "test"}