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 /
  • Help Room /
avatar image
0
Question by M_Yassin · Dec 21, 2017 at 12:55 PM · savingissuescompatibility

Playerprefs saving player data in xml file, the functions works for my other android phone except for my one redmi phone?

Redmi 4a which has been updated to android version 6 the function saves player exp and other stats such as attack, health ,etc a test build that was testing this function whether it will save and load the data when player exits and relaunch the app. this function works on my other test device which holds two different version of android, one is version 5 and the other is version 8 the application is built for android version between 5 to the highest version.

GameManager Code //saveAllCharacters public void SaveAllCharacters() { for (int i = 0; i < Character.Length; i++) { SaveManager.instanceSM.SaveCharacter(Character[i].gameObject); } }

 //loadAllCharacters
 public void LoadAllCharacters() {
     for (int i = 0; i < Character.Length; i++)
     {
         SaveManager.instanceSM.LoadCharacter(Character[i].gameObject);
     }
 }

save Manager //save Character public void SaveCharacter(GameObject Character) { //temp stats holder cStat = new CharacterStat();

     //Character Stats
     cs = Character.GetComponent<CharacterStatus>();

     //moving stats to temp
     cStat.health = cs.health;
     cStat.maxHealth = cs.maxHealth;
     cStat.maxHealthUpgrade = cs.maxHealthUpgrade;
     cStat.upgradeNHealth = cs.upgradeNHealth;
     cStat.attack = cs.attack;
     cStat.maxAttack = cs.maxAttack;
     cStat.upgradeNAttack = cs.upgradeNAttack;
     cStat.defence = cs.defence;
     cStat.maxDefence = cs.maxDefence;
     cStat.upgradeNDefence = cs.upgradeNDefence;
     cStat.exp = cs.exp;
     cStat.maxExp = cs.maxExp;
     cStat.lvl = cs.lvl;
     cStat.maxLvl = cs.maxLvl;
     cStat.isOwned = cs.isOwned;

     //saving it playerPrefs with charater name
     PlayerPrefs.SetString(Character.gameObject.name,Helper.Serialize<CharacterStat>(cStat));
 }


 //Load Character
 public void LoadCharacter(GameObject Character) {
     //character Stats
     cs = Character.GetComponent<CharacterStatus>();

     if (PlayerPrefs.HasKey(Character.gameObject.name))
     {
         //moving character stats from playerPrefs to temp holder
         cStat = Helper.Deserialize<CharacterStat(PlayerPrefs.GetString(Character.gameObject.name));
         
         //moving temp stats to character stats
         cs.health = cStat.health;
         cs.maxHealth = cStat.maxHealth;
         cs.maxHealthUpgrade = cStat.maxHealthUpgrade;
         cs.upgradeNHealth = cStat.upgradeNHealth;
         cs.attack = cStat.attack;
         cs.maxAttack = cStat.maxAttack;
         cs.upgradeNAttack = cStat.upgradeNAttack;
         cs.defence = cStat.defence;
         cs.maxDefence = cStat.maxDefence;
         cs.upgradeNDefence = cStat.upgradeNDefence;
         cs.exp = cStat.exp;
         cs.maxExp = cStat.maxExp;
         cs.lvl = cStat.lvl;
         cs.maxLvl = cStat.maxLvl;
         cs.isOwned = cStat.isOwned;
     }
     else
     {
         cStat = new CharacterStat();
         SaveCharacter(Character);
     }
 }

*Note ignore spelling error, the has been edited to be post here

Thank you ^^

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

0 Replies

· Add your reply
  • Sort: 

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

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity limiting device compatibility 1 Answer

Problem in Saving Score? 2 Answers

High score resets with score? 0 Answers

What is the most common way to implement save in Apple TV / tvOS? How does it implement PlayerPrefs? 1 Answer

Get public static list 0 Answers


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