Saving Vector2 coordinates as waypoints to dynamic array

Hi there,

I am wanting to write a script that allows me to control my player car and every half second or so, store the X/Y coordinates to an array, increasing the size of the array as it does so. Then I can use the data stored in the array as waypoints for my AI cars to drive between (can also use it as ghost data).

I understand how to set up arrays and add the data to them, the question I have is… how do I make it so that I can access that data inside the array and store it for use with another car without being zeroed every time I run the scene?

Would I need to save the data to an external file and then read it back in? I’m a bit of a Unity/game dev noob, so this stuff seems a little tricky to me but once I have the “idea” of how to do it, I should be able to work it out. I’m not asking for scripts or code samples.

The only way I could make it work right now would be to print the values to the debug console and manually go through them and add them to the AI script by hand… that seems silly. LOL.

Any help would be greatly appreciated :wink:

You can use playerprefs to do that. Unfortunately, there isn’t a Get/SetArray, so you can use this instead. (From Eric5h5)