• 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 achieve is it auto saves while you're playing, and on the menu, there is a Load button. This 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 this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if(Application.loadedLevel != currentLevel)
         {
             currentLevel = Application.loadedLevel;
             PlayerPrefs.SetInt("LastLevelLoaded",currentLevel);
         }
     }
 }

And this 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 nothing. 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

  • Sort: 
avatar image
Best Answer

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

I think 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. This 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 this problem, but I believe this 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 this 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

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

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

Spawning loot only the first time a level is loaded 1 Answer

Saving and loading an int variable on Android 1 Answer

How do I make a level code system? 3 Answers

Do we have to open SavedGame every time we do a CommitUpdate when using cloud PlayGames services? 1 Answer

Seeing slow performance on play-games-plugin-for-unity OpenWithAutomaticConflictResolution 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