Hello I hae this script that should sae data about GameObjects to a json file:
public void SaveData()
{
List<string> jsonStrings = new List<string>();
foreach (GameObject sceneObject in toolbar.sceneObjects)
{
string name = sceneObject.name;
jsonStrings.Add(name);
string tag = sceneObject.tag;
jsonStrings.Add(tag);
Vector3 position = sceneObject.transform.position;
jsonStrings.Add(position.ToString());
Vector3 rotation = sceneObject.transform.eulerAngles;
jsonStrings.Add(rotation.ToString());
Vector3 scale = sceneObject.transform.localScale;
jsonStrings.Add(scale.ToString());
Component meshFilter = sceneObject.GetComponent<MeshFilter>();
jsonStrings.Add(meshFilter.ToString());
Component Renderer = sceneObject.GetComponent<Renderer>();
jsonStrings.Add(Renderer.ToString());
Component collider = sceneObject.GetComponent<Collider>();
jsonStrings.Add(collider.ToString());
Component rigidbody = sceneObject.GetComponent<Rigidbody>();
jsonStrings.Add(rigidbody.ToString());
Component light = sceneObject.GetComponent<Light>();
foreach(MonoBehaviour script in sceneObject.GetComponents<MonoBehaviour>())
{
string scriptName = script.name;
jsonStrings.Add(scriptName);
if(script.name == "ChildObject")
{
GameObject extender = sceneObject.GetComponent<ChildObject>().childObject;
jsonStrings.Add(extender.ToString());
}
if(script.name == "Portal")
{
Vector3 coordinates = sceneObject.GetComponent<Portal>().coordinates;
jsonStrings.Add(coordinates.ToString());
GameObject player = sceneObject.GetComponent<Portal>().player;
jsonStrings.Add(player.ToString());
}
if(script.name == "YPad")
{
bool touching = sceneObject.GetComponent<YPad>().touching;
jsonStrings.Add(touching.ToString());
AudioClip sound = sceneObject.GetComponent<YPad>().launch;
jsonStrings.Add(sound.ToString());
}
if(script.name == "SetPlayerPrefs")
{
int thislevel = sceneObject.GetComponent<SetPlayerPrefs>().ThisLevel;
jsonStrings.Add(thislevel.ToString());
int thislevelmaxscore = sceneObject.GetComponent<SetPlayerPrefs>().ThisLevelMaxScore;
jsonStrings.Add(thislevelmaxscore.ToString());
GameObject player = sceneObject.GetComponent<SetPlayerPrefs>().Player;
jsonStrings.Add(player.ToString());
}
}
}
string jsonData = JsonUtility.ToJson(jsonStrings, true);
File.WriteAllText(localLevelLocation + "/" + properties.levelName + "_data.json" , jsonData);
}
But the file that is created is empty except of two curly brackets