How to get all the GameObjects positions into a .txt file?

I have been trying to make a save feature, but I don’t know how to get all the GameObjects positions and then get all those positions into a .txt file.

If there’s a better way then let me know.

Read this link, it was answered previously:

Save object using playerprefs

Hope this helps!

Martin

Hi!

Litterally:

public void	Start()
{
	try
	{
		System.IO.StreamWriter	saveFile = new System.IO.StreamWriter("savefile.txt", false);
		Transform[]	transforms = GameObject.FindObjectsOfType(typeof(Transform)) as Transform[];

		foreach (Transform t in transforms)
		{
			this.saveFile.WriteLine(t.position);
		}
	}
	catch (System.Exception ex)
	{
		Debug.Log(ex.Message);
	}
	finally
	{
		saveFile.Close();
	}
}

The result can be the following:

(1.0, 0.0, 0.0)
(3.0, 0.0, 0.0)
(5.0, 0.0, 0.0)
(7.0, 0.0, 0.0)
(2.5, 1.2, -19.0)
(-82.2, -1.2, 8.1)
(0.0, 1.0, -10.0)

This is not the greatest solution, but it does what you are asking for.