Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by riku_nishino · Aug 07, 2011 at 04:44 PM · playerprefssave

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by SisterKy · Aug 07, 2011 at 08:48 PM

Quick answer
Long answer

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image riku_nishino · Aug 10, 2011 at 06:46 PM 0
Share

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 ^^

avatar image SisterKy · Aug 10, 2011 at 07:57 PM 0
Share

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.

avatar image riku_nishino · Aug 13, 2011 at 03:11 PM 0
Share

thx Sister$$anonymous$$y, but how to hit check$$anonymous$$ark top ? i hit it but it say "i dunt hv permission.." ?

avatar image SisterKy · Aug 13, 2011 at 03:19 PM 0
Share

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...?

avatar image riku_nishino · Aug 14, 2011 at 05:04 AM 0
Share

oh yes i can.. hehe xory i think for vote, thx thx Sister$$anonymous$$y

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges