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.

You probrably need to make something better than Player Prefs, Id Recommend checking out this link:

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)


public static List<Vector3>  myList;

or make a storage object and
DontDestroyOnLoad (yourStorageObject);