Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 zachary.collins · Apr 23, 2012 at 06:05 PM · javascriptloadingsavinghealth

Save Player Health and stats

I am making a game where you get into random encounters and are moved to another scene where a turned based battle takes place. I need to save my players health for when he moves back into the world scene and then load it again once he re-enters the battle scene. I'm pretty new to javascript so please try to bear with me. Thanks in advance.

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
0

Answer by BiG · Apr 23, 2012 at 06:50 PM

You can use PlayerPrefs!

 PlayerPrefs.SetInt("Health", player_health); //Stores the health variable

 player_health = PlayerPrefs.GetInt("Health"); //Retrieves the health variable

Another example here.

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 Fabkins · Apr 23, 2012 at 06:57 PM 0
Share

Really? I wouldn't thought PlayerPrefs is the appropriate tool for save information. $$anonymous$$ore for things like remembering your graphic , sound , etc options.

avatar image BiG · Apr 23, 2012 at 07:04 PM 1
Share

It's the appropriate tool. He has to remember informations between a scene transition.

avatar image Fabkins · Apr 23, 2012 at 07:10 PM 0
Share

And what happens when he want to store the inventory of character, what missions he completed, etc in the future?

He needs to effectively do a game save. I just don't think PlayerRefs is the appropriate approach to this. On Windows its stored in the Registry which gives some indication of the purpose of this.

avatar image zachary.collins · Apr 23, 2012 at 11:29 PM 0
Share

what would you suggest then Fabkins?

avatar image Fabkins · Apr 23, 2012 at 11:49 PM 0
Share

Saving it as a file. X$$anonymous$$L is often a good choice as its human readable and the there is some reference script:

http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_X$$anonymous$$L

That one actually also includes a save menu.

There is a good thread on the topic here:

http://answers.unity3d.com/questions/8480/how-to-scrip-a-saveload-game-option.html

If its really as simple as just a few stats then it is certainly cracking a nut with a sledgehammer and PlayerPrefs would do. But as soon as you need something more than just value pairs and require structure you need to write to a file.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Save data from one scene to another? 0 Answers

Retrieving basic Strings and Ints from XML Files (JS) 0 Answers

Damage/Healing over time 1 Answer

Saving/Loading Problems 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