- Home /
how autosave for reduce blood
hey.. i hv a question about autosave on function OnGUI, i want to make a countdown pet status..
then.. when i quit the game, i can continue it.
example : i start the game when my blood status is 100%, and that blood status will be
reduced until 40%, then i quit the game.
i want it to be 40% when i resume the game
can anybody help me .. thank you very much
Answer by SisterKy · Aug 07, 2011 at 08:48 PM
To 'auto' the save, just call Playerprefs.SetInt before you call Application.Quit on your Quit-button.
For auto-load, call Playerprefs.GetInt in function Start() of your player-health-script.
Greetz, Ky.
thx sisterky.. i have try it and it's work to save.. but i confuse to use playerprefs.haskey now, i must check it like this
if(playerprefs.haskey($$anonymous$$ySaveData))
{ Do$$anonymous$$yFunction(); } else { Do$$anonymous$$yFunction2(); }
function Do$$anonymous$$yFunction(adj : int) { curStatusSave += adj;
if(curHappiness < 0) {
curHappiness = 0;
}
if(curStatusSave > maxHappiness) {
curStatusSave = maxHappiness;
}
happinessBarLength = curStatusSave}
function Do$$anonymous$$yFunction2(adj : int) { curHappiness += adj;
if(curHappiness < 0) {
curHappiness = 0;
}
if(curHappiness > maxHappiness) {
curHappiness = maxHappiness;
}
happinessBarLength = curHappiness;
}
and my problems is, i have 2 same function, can i do my function in one script ? im really - really basic in scripting..but thx for Your helo..i appreciated ^^
I'm not sure what you are trying to do...
the two functions all by themselves should be no problem at all.
The computer is stupid ;) it won't notice the functions are the same.
But you could also do if(playerprefs.haskey($$anonymous$$ySaveData)) { Do$$anonymous$$yFunction(); } else { Do$$anonymous$$yFunction(); }
so you don't have to define the 'same' function with two names.
But if you want to do the things in Do$$anonymous$$yFunction(); [or Do$$anonymous$$yFunction2();] anyway, the 'if' doesn't make any sense. Only use 'if' if you want to do different things for different conditions. Just call Do$$anonymous$$yFunction(); without asking for playerprefs.haskey($$anonymous$$ySaveData)...?
But I'm sorry, I don't really know how playerprefs work. I never used them myself, just knew the links... best you open a new question and explain what you want to do in more detail.
If my answer solved your original question, please 'accept' it (hit the little check-mark top left of my answer)
Greetz, $$anonymous$$y.
thx Sister$$anonymous$$y, but how to hit check$$anonymous$$ark top ? i hit it but it say "i dunt hv permission.." ?
Huh? That's strange... you should be able to do it. You are logged in, so it should not be a problem =/ $$anonymous$$aybe a bug with UnityAnswers...?
oh yes i can.. hehe xory i think for vote, thx thx Sister$$anonymous$$y
Your answer
![](https://koobas.hobune.stream/wayback/20220612172324im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Save/load playerprefs 2 Answers
Saving and Loading data in one scene 1 Answer
DeleteAll not working on android? 0 Answers
Null Reference Exception even after check 1 Answer
How to save an Audio Mixer's value wich is adjusted with a Slider? 1 Answer