I’m making a Match Three GAme with lives being used for attempts and have managed to implement a time that increases lives dependent on time. I’m having trouble with using Player.Prefs to move that int between scenes though, is this due to the number increasing occasionally?
I have read through the Unity documentation and can’t figure it out myself due to my lack of programming skill. Is this possible to do and if so how would I go about implementing it so the lives save over multiple scenes?
I can provide the code to my timer if needed but any help would be appreciated, thank you!
PlayerPrefs is not the tool you should be using for this. Try using DontDestroyOnLoad to keep a game object around when you load a new scene - that way your timer will keep running seamlessly.
If you are using playerprefs just to keep track of lives, you shouldn’t have issues using it. You can easily set or get the value. I’m not sure why you are having issues with it between scenes.
If you do use DontDestroyOnLoad as @StarManta suggested, your timer can move between scenes and keep ticking away and add lives as it’s suppose to no matter what scene you are in. You could technically keep track of those lives in the timer script as well, but you might need to also include a system to make sure the player isn’t out of lives, closes app, and then logs back in to get full lives back, which means recording how many lives they had last, and possibly a timestamp so you can check how much time has passed (unless you only want to restore lives when they are in your game, which I don’t think is the normal behavior).
Just some things to keep in mind.
@StarManta @Brathnann So when using DontDestroyOnLoad is there a way to avoid getting a duplicate at all since my game is set up in a loop after you finish a level so you’re sent back to the menu. I’m thinking you could set up a beginning scene that has all persistent objects so they won’t be duplicated but my Lives Counter requires a gameobject to be able to assign a UI text object to it, how could i get around this?