Hey i have several pieces of a grid, call them tiles. These tiles all share the same script: Tile.cs
These pieces are prefabs that are instantiated so they arent active in the scene until Start()
In Tile.cs we have a public int called "State" which indicates the state of the tile and it changes when the int changes (when its 0 its default).
Lets say for example when i click on one of these tiles with a raycast i want to change the int of the gameobject to 1. When the tiles state is changed to 1 it will be marked.
Now i want to save this change with PlayerPrefs. I have a save button in my game that will save all of the moves i made. And when i reload a certain scene these saved changes shall be loaded.
However how do i save the int for just this gameobject that im accessing?
I tried saving like this:
void SaveTiles()
{
if (ui.isSaved)
{
PlayerPrefsX.SetVector3("currState" + tile_ID.ToString(), State);
}
}
State is just a int that is at 0 when default:
tile_ID is:
private static int tile_ID;
private static int thisTile_ID = 0;
void Start ()
{
tile_ID = thisTile_ID;
thisTile_ID++;
}
So each tile get its own ID and i can use this to save individual keys for each tile when i do PlayerPrefs. ui.isSaved is a bool that indicates when i push the save button.
I used the ID to save playerprefsX and save the vector3's of all the tiles too but this change doesnt make a difference since their position doesnt really change. I dont know if this is useless or necessary.
Thanks for the help
↧