Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

How to save/load a ScrollRect's position using PlayerPrefs on scene change?

$
0
0
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(); } }

Viewing all articles
Browse latest Browse all 1333

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>