Hi there, I am trying to loop through all the gameobjects with a tag and save their data like position, rotation etc… to a JSON file, however the JSON only contains data for the last object it loops through.
What’s weird is when I Debug.Log(json.ToString()); it returns the JSON data just fine.
SaveLoadObjects data = new SaveLoadObjects();
Debug.Log("Saving file as level" + levelInt + "...");
GameObject[] objects = GameObject.FindGameObjectsWithTag("Object");
foreach (GameObject obj in objects)
{
data.objName = obj.name;
data.posX = obj.transform.position.x;
data.posY = obj.transform.position.y;
data.posZ = obj.transform.position.z;
string json = JsonUtility.ToJson(data, true);
Debug.Log(json.ToString());
File.WriteAllText("level" + levelInt + ".phbl", json);
}

