Unity study notes–the use of PlayerPrefs for data persistence

Unity study notes–Usage of PlayerPrefs for data persistence Data persistence PlayerPrefs related PlayerPrefs is a class in the Unity game engine used to store and access player preferences and data in the game. It can be used to save the player’s game progress, setting options, highest scores and other information. PlayerPrefs stores data in local files so data is persisted across game restarts. //PlayerPrefs data storage is similar to key-value pair storage, one key corresponds to one value //Provides methods to store 3 types of data int float string //Key: string type //Value: int float string corresponds to 3 APIs PlayerPrefs.SetInt(“myAge”, 18); PlayerPrefs.SetFloat(“myHeight”, 177.5f); PlayerPrefs.SetString(“myName”, “TonyChang”); //Directly calling Set-related methods will only store the data in memory. //When the game ends, Unity will automatically save the data to the hard disk. //If the game does not end normally but crashes, the data will not be saved to the hard disk. //As long as this method is called, it will be stored in the hard disk immediately. PlayerPrefs.Save(); //PlayerPrefs is limited. It can only store 3 types of data. //If you want to store other types of data, you can only reduce the precision or increase the precision for storage. bool…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索