- Home /
Record x,y,z position of object in Textfile dynamically for playback
I want to record the position of a gameobject as it moves and load this back in if a certain event is triggered. This would then be applied to a different gameobject.
So if a cube were to be moved about by a user the position is recorded as it moves. When a certain event is triggered (on keypress for example) then a 2nd cube would be moved in the same way but from its own starting position.
I have looked at playerprefs but from what i understand this would only work for saving a single position and loading an object back to that position.
Is this sort of thing possible? If so is there a standard way to set, for example, the saving of the coordinates to be done every 0.1 seconds?
Being a newbie it is likely i just dont know the right keywords to be searching to figure this out myself. Any help in steering me in the right direction would be greatly appreciated.
Answer by kramcomposer · Mar 04, 2013 at 05:33 PM
You probrably need to make something better than Player Prefs, Id Recommend checking out this link: http://forum.unity3d.com/threads/44559-Saving-Game-beyond-PlayerPrefs-XML-ISerializable-etc
QUESTION: Are you trying to make it so the player can playback after leaving the game? If not, you can just store a List as a Static Member, and it will persist throughout the game (untill shutdown)
IE:
public static List<Vector3> myList;
or make a storage object and
DontDestroyOnLoad (yourStorageObject);
@kramcomposer Thanks for that i'm about to read that thread now. In answer to your question though, yes i need to playback AFTER the game has been closed. this functionality will be extended for something i want to do in a game but i need to first have a way to store and load the positions before i can make any progress.
The end result is multiple recordings that can be selected by a user, causing the 2nd object to basically have its recorded movements played back.