saR
1
Hi, I’m creating a slider game for mobile.
My problem is that when the player makes progress and moves the squares around I want to save the position of each square , the puzzle instantiates when the scene starts (its on the start function, what it does it creates a 3x3 and divides the image in quads, so each quad is a piece of the image).
I don’t really understand how to save this type of objects, I’ve managed to learn how to save the points,the level and the time, but not the position of the objects.
The way I can imagine it could be done is by traveling through the array then store each position every time an object is moved but I dont know how to do it.
They are Vector2Int if you need more information I can provide.
Thanks in advance 
qobion
2
If you want to save vectors or arrays in playerprefs you can convert it to string and save this string with some formatting so then you can convert it again to array back. This is look like this:
Vector2Int [] positions;
void SavePositions()
{
string s = "";
foreach (Vector2Int c in positions)
{
s += string.Format("{0}:{1}:",c.x,c.y);
}
PlayerPrefs.SetString("MyPositions", s);
}
void LoadPositions()
{
string s = PlayerPrefs.GetString("MyPositions");
if (s == null)
return;
string[] p = s.Split(':');
for (int i = 0; i < p.Length; i+=2)
{
positions_.x = System.Convert.ToInt32(p*);*_
positions*.y = System.Convert.ToInt32(p[i+1]);*
}
}
saR
3
Thank you for your answer @qobion ! I think I understood the code you’ve written.
So what I should do is save each position by having a public static Vector2Int on the blocks script so I save each position and then replace it in the code you just said.
The thing is that I dont really understand where to replace it , I’m so sorry , I just finished my first year with c# and in the code you just said there’s some syntaxis I dont understand, but anyways , thank you for your response I really apreciate it !