This means that if you want to have more than one save file for your application, you need to get creative. Method of saving dataįirst of all, PlayerPrefs saves data on a per-application basis. Right away, some things should raise some eyebrows. A good first step in this process is to check the docs for PlayerPrefs. Let’s start by taking a closer look at PlayerPrefs to see if it’s something we want to use to save our game data. The longer answer is that saving and loading data in Unity is actually a very deep topic without a clear best solution. The short answer is that saving a game state like this is generally a bad idea. This certainly seems to be about as easy as it gets, so it’s time to save some data, right? You can set a default return value if you haven't saved a "Level" yet with the second parameterĬurrentLevel = PlayerPrefs.GetInt("Level", 0) ![]() When you’re ready to load, getting the saved value is just as easy: PlayerPrefs.SetInt("Level", currentLevel) currentLevel is an integer variable representing the level the player is on All you need to do to save the level is the following: Well, this looks pretty easy in PlayerPrefs. You’ve decided you want to save the level your player is on when they quit the game so that the correct level loads back up when they start again. Let’s say you’ve made a simple game with some number of levels. With PlayerPrefs, you can have an easy-to-use interface that allows you to start persisting some data! We’ll also discuss reasonable alternatives to using PlayerPrefs. In this article, we’ll go over what PlayerPrefs is, how, when, and when not to use it. The simplest solution is a Unity class called PlayerPrefs. From this search, you may be surprised that there are quite a few different answers, all varying in complexity. If you’re like most of us, your first instinct might be to do a quick search on how to save player data in Unity. Whether you’re relatively new to developing in Unity or you’ve got a few projects under your belt, you’ve most likely realized how useful it would be for players to save data. ![]() Why you should (or shouldn’t) save data with Unity’s PlayerPrefs Brian Drake Follow Brian is the owner of UpRoom Games, a small independent game studio focused on creating unique experiences and sharing game dev knowledge in Unity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |