K
K
KeysCG2021-10-05 14:51:54
Unity
KeysCG, 2021-10-05 14:51:54

How to keep unique PlayerPrefs values ​​per level?

Good day!
Please help me figure out how to save PlayerPrefs values ​​at each level!
That is, let's say I have 3 levels, they are gradually opened with the preservation of lives and cartridges, but when I want to replay the previous level, I have the last value of lives and cartridges, but how to make it so that at each level the values ​​\u200b\u200bthat were saved at passing the previous level?
That is, for example, after the first level, I have 50 lives left and they are transferred to the second, and after passing the second, 30 lives are left and I have a need to replay the second level and it is necessary that 50 lives that were lost after the first level be preserved on this level, and it turns out that when I go to the second level, 30 lives are loaded for me, which are after the third level :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2021-10-05
@freeExec

Those. you just save жизнь=50instead of savingжизнь_на_уровне_2=50

K
KraGen.Developer, 2021-10-05
@KraGenDeveloper

I would do it like this:
-If at the end of the lvl buttons pop up or something like that, then you can simply enter in the button actions (public void urButton()) PlayerPrefs.Save();
-If there is nothing like that, then make a trigger and run a script to it:

public void OnTriggerEnter(Collider other){
if(other.tag == "Player"){
    PlayerPrefs.Save();//Сохраняем ВСЕ значения ПЛеерПрефс
}
}

Something like this)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question