The second Debug.log(); show a value of 0, any ideas why the data isn’t being correctly assigned?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Tests : MonoBehaviour
{
public string map = "test.json";
public static string LoadJsonMapFile(string path)
{
string filePath = path.Replace(".json", "");
TextAsset targetFile = Resources.Load(filePath) as TextAsset;
return targetFile.text;
}
void Start()
{
string jsonMapData = LoadJsonMapFile(map);
RootObject jsonMap = new RootObject();
jsonMap = JsonUtility.FromJson<RootObject>(jsonMapData);
Debug.Log("Name " + jsonMap.name + " : Desc " + jsonMap.description);
Debug.Log("Version " + jsonMap.map.version);
}
public class Map
{
public int version;
}
public class RootObject
{
public string name;
public string description;
public Map map = new Map();
}
}
My simplified Json file:
{
"name": "Shadow Realm",
"description": "A spooky Haloween inspired map",
"map": {
"version": 79
}
}