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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
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
Add comment · 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
0

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving/loading inherited class scripts (C#) 1 Answer

Save and Load Audio from web 0 Answers

Saving and Loading from different scene 0 Answers

BinaryFormatter - Save and Load lists of data? 0 Answers

Saving ScriptableObjects in EditorWindow 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