I have the following classes and json file, i thought id followed the documentation exactly but I am clearly wrong. Can anyone see why I get an error just saying : INVALID VALUE in my unity console:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
[Serializable]
public class DataReader
{
public float[] x;
public float[] y;
public float[] z;
}
GameController:
public class GameController : MonoBehaviour { public static GameController instance;
DataReader dataReader;
private string gameDataFileName = "level1.json";
private void Awake()
{
dataReader = JsonUtility.FromJson<DataReader>(gameDataFileName);
instance = this;
}
void Start () {
// create level:
print("DATA: " + dataReader.x[0]);
}
}
and the json is stored in StreamingAssets folder (I also tried a copy in Resources folder):
{
"x": [{1},{1},{1},{1}],
"y": [{1},{1},{1},{1}],
"z": [{1},{2},{3},{4}]
}