I am working on the UI design for a game that has two scene; 'scene one' is the level select and 'scene two' is the game. 'Scene one' has all the levels inside of a ScrollRect. Currently the position of the ScrollRect is resetting on load. I would like the ScrollRect to save its position on exit and then load that position back on reopen.
I figured the best way to do this was through PlayerPrefs. After looking at similar examples I wrote the code out below but am still getting an Error CS1729 regarding the vector3 and I am at a loss. Would love to hear from you if you have faced this issue before or know about PlayerPrefs, thank you!
public float pX;
// Use this for initialization
void Start()
{
if (PlayerPrefs.GetInt ("Saved") == 1)
{
pX = PlayerPrefs.GetFloat ("x");
transform.position = new Vector3 (pX);
PlayerPrefs.SetInt ("Saved", 0);
PlayerPrefs.Save ();
}
}
// On object disable/destory
void OnDisable()
{
PlayerPrefs.SetFloat("x", transform.position.x);
PlayerPrefs.SetInt("Saved", 1);
PlayerPrefs.Save();
}
}
↧