- Home /
Question by
tgnass · May 07, 2013 at 09:51 AM ·
gameobjectssave-to-filepositionstext file
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.
Comment
Answer by SubatomicHero · May 07, 2013 at 10:37 AM
nope, none
scope the UnitySerializer by Whydoidoit, though, it's pretty bonkers awesome.
Answer by Mikilo · May 07, 2013 at 11:53 PM
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.