Answer the question
In order to leave comments, you need to log in
Storing a 2D array in JSON UNITY C#?
When saved, everything is preserved except the Map, which is Map = new int[width, height];
But there is nothing in the JSON file at this point.
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftAlt))
{
if (Map != null)
{
mapInf.MapData = Map;
mapInf.width = width;
mapInf.height = height;
mapInf.MapOffset = MapOffset;
mapInf.sprites = sprites;
File.WriteAllText(path, JsonUtility.ToJson(mapInf));
Debug.Log("Saved!");
}
}
}
[Serializable]
public class MapInfo {
public int[,] MapData = new int[0,0];
public int width;
public int height;
public int MapOffset;
public Sprite[] sprites;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question