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 nikoyal · Apr 20, 2017 at 10:57 AM · serialization

Cant save/load game data

Well im "making" a game so i can practice and i want to save my game stats ive been looking alot on the internet but couldnt actually save this game data i dont know why. I know the code should be simple so if you can give me an idea or a code i would be very happy !!

 using UnityEngine;
 using System.Collections;
 
 [Serializable]
 public class Storage : MonoBehaviour {
     //money
     public static int money = 0 ;
     public static int moneymultiplier = 1;
     public static int moneymultipliercost = 50000;
     //stats&hp
     public static int health = 0;
     public static int RatHelath = 50;
     public static int DogHealth = 200;
     public static int ChickenHealth = 600;
     public static int HumanHealath = 1500;
     public static int BossHealth = 100000;
     public static int TapDMG = 1;
     public static bool SpriteIsTriggered = false;
     public static int Rats = 0;
     public static int Dogs = 0;
     public static int Chicken = 0;
     public static int Human = 0;
     public static int boss = 0;
     //hunger
     public static int RatsHunger = 5;
     public static int DogsHunger = 10;
     public static int ChickenHunger = 15;
     public static int HumanHunger = 20;
     public static int bossHunger = 50;
     //fed
     public static int RatFed = 0;
     public static int DogFed = 0;
     public static int ChickenFed = 0;
     public static int HumanFed = 0;
     public static int BossFed = 0;
     //unlock sprites
     public static bool Ratunlocked = false;
     public static bool Dogunlocked = false;
     public static bool Catunlocked = false;
     public static bool Humanunlocked = false;
     public static bool bossunlocked = false;
     //cup
     public static int CupDMG = 75;
     public static int CupUpgrade = 1;
     public static int CupUpgradePrice = 5000;
     //level
     public static int Level = 0;
     public static int exp = 0;
     public static int needed = 50;
 }
 








Comment
Add comment · Show 1
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 PizzaPie · Apr 21, 2017 at 11:56 AM 0
Share

Check this out on how to write and load custom data files from disc, as for the playerPrefs if you going to save a couple values it should suffice and it is easier but I highly recommend to spend some time learning the methods above. Cheers.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by RealGamesStudio · Apr 20, 2017 at 12:41 PM

Why dont you use PlayerPrefs? Check out this link - https://docs.unity3d.com/ScriptReference/PlayerPrefs.html

Comment
Add comment · 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
0

Answer by nikoyal · Apr 21, 2017 at 09:22 AM

Tried this

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class SaveGame : MonoBehaviour {
 
     // Use this for initialization
     public void Save () {
         PlayerPrefs.SetInt ("Money", Storage.money);
     }
     
     // Update is called once per frame
     public void Load () {
         Storage.money = PlayerPrefs.GetInt ("Money");
     }
 }
 

and this

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class SaveGame : MonoBehaviour {
 
     // Use this for initialization
     public void Save () {
         PlayerPrefs.SetInt ("Money", Storage.money);
     }
     
     // Update is called once per frame
     public void Load () {
         Storage.money = PlayerPrefs.GetInt ("Money");
     }
 }
 

It didnt wok :(

Comment
Add comment · 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

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

103 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

Related Questions

[CLOSED]Problem with serialization after PUN update 2 Answers

Cannot read past end of stream, MemoryStream 1 Answer

How to write a Story Event System with ScriptableObjects? 0 Answers

can not open project stuck on white screen 0 Answers

How to serialize a List of ContentPacks (from Morph3D) in Photon Unity Networking? 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