• 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
Question by apie2546 · Nov 24, 2015 at 06:45 PM · loadingsavingplayerprefsx

Loading and Saving

Trying to implement a basic saving system into my ball rolling game. Basically the functionality I am trying to ac$$anonymous$$eve is it auto saves w$$anonymous$$le you're playing, and on the menu, there is a Load button. T$$anonymous$$s is my saving class, attached to a game object using UnityEngine; using System.Collections;

 public class saving : MonoBehaviour {
 
     public static int currentLevel;
 
     void Awake()
     {
         DontDestroyOnLoad (transform.gameObject);
         currentLevel = PlayerPrefs.GetInt("LastLevelLoaded");
     }
 
     // Use t$$anonymous$$s for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if(Application.loadedLevel != currentLevel)
         {
             currentLevel = Application.loadedLevel;
             PlayerPrefs.SetInt("LastLevelLoaded",currentLevel);
         }
     }
 }

And t$$anonymous$$s is a loader, attached to a game object as well using UnityEngine; using System.Collections;

 public class Load : MonoBehaviour {
 
     void Awake()
     {
         DontDestroyOnLoad (transform.gameObject);
     }
     
     public void Loaders()
     {
         Application.LoadLevel (saving.currentLevel);
         // Call the LevelManager and set the last level.
 
     }
     
 
         
 
 }

When I initially press load on the menu, it reloads my "loading" scene, and when I go to play the main level, and then I click menu, and attempt to load it, it does not$$anonymous$$ng. It loads the menu again I believe.

Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by TheAltbacker · Nov 24, 2015 at 08:36 PM

I t$$anonymous$$nk you could just exclude your Menu(s) or scenes you don't want the script to save by adding

(Application.loadedLevel != (index of the menu you want to exclude))

to your if statement in the Update() of saving. T$$anonymous$$s way, if the scene you loaded is included in the if statement, it won't be saved. You could also use

(Application.loadedLevelName != "MENUNAME" ))

to refer to your scenes by their names if that is easier. There might be better, more elegant solutions to t$$anonymous$$s problem, but I believe t$$anonymous$$s should work. Cheers.

W.B.

Comment
apie2546

People who like this

1 Show 3 · 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 apie2546 · Nov 24, 2015 at 11:41 PM 0
Share

Thanks! I added that in however It still will not load the level

avatar image TheAltbacker · Nov 25, 2015 at 10:41 AM 0
Share

Are all your references okay? I mean, are you sure, that everything gets called when and how you want it to? You might want to Debug your script.

avatar image apie2546 TheAltbacker · Nov 27, 2015 at 06:26 PM 0
Share

Yeah, it still wouldn't go through, so I ended up changing the idea and went with a world unlock tutorial: http://www.thegamecontriver.com/2014/09/create-level-lock-unlock-system-unity-46.html

avatar image

Answer by apie2546 · Nov 27, 2015 at 06:26 PM

I solved t$$anonymous$$s by just using a level unlock system: http://www.thegamecontriver.com/2014/09/create-level-lock-unlock-system-unity-46.html

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to allow coins to increase its Player.Prefs file and save, but then load it again next time. 1 Answer

Saving data with files 1 Answer

How to save home and patrol points along with the enemies? Please 0 Answers

save and load 1 Answer

How to Serialize or Save a List of GameObjects 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