• 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 /
avatar image
2
Question by worldofcars · Feb 12, 2012 at 02:42 PM · loadlevel

If start game --> load last level where you have played on it

Hello. I have a big question. I am making a 3D Racing game using the unity3d engine. The game works link this: You start at level 1 with one car. You have 2 Minutes to drive around the race track. If you made it you reach level2 and unlock a new car. But there is a problem. Your mother calls you to go eating and you close the game. After eating you come back and open the game and you want to play your level 2...

HOW CAN I MAKE IT THAT WHEN YOU CLOSE THE GAME IN LEVEL 2 AND OPEN IT AGAIN THAT YOU MUST NOT BEGIN AGAIN AT LEVEL1 ??? How can I load/save the lastest level you have reached??? Some scripts will be helpful:=)

Comment
Add comment · Show 3
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 dragidragi · Oct 02, 2017 at 08:08 PM 0
Share

I have problem. When I start game on Android my first scene with play button do not work.

avatar image DevmobiStudios · Oct 02, 2017 at 08:24 PM 0
Share

same here what to do

avatar image FortisVenaliter DevmobiStudios · Oct 02, 2017 at 08:42 PM 0
Share

Open a new question ins$$anonymous$$d of resurrecting a 5-year-old one.

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by BiG · Feb 12, 2012 at 03:02 PM

You can use PlayerPrefs. Whenever you reach a new level, use the Set() method to update the last level reached, in a similar way:

 //Here, you are in the function that updates the last level reached
 //...
 level_index++;  //Because you've reached the next level
 PlayerPrefs.SetInt("Last_Level", level_index);



And, at the beginning of the game, use Get() method to load last level reached:

 //...
 level_index = PlayerPrefs.GetInt("Last_Level");
 Application.LoadLevel(level_index);



If things aren't clear yet, you can check for another example in this thread of the Forum (check bigkahuna's answer):

http://forum.unity3d.com/threads/42398-Example-of-using-Player-Prefs-to-save-and-get-a-variable.

At last, pay attention to handle the special case regarding the last track of the game (you cannot make level_index++, in that case).

Comment
Add comment · Show 8 · 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 worldofcars · Feb 12, 2012 at 03:39 PM 1
Share

AHH GREAT IT WOR$$anonymous$$S :D Thank you for the answer;)

avatar image BiG · Feb 12, 2012 at 03:41 PM 0
Share

That's good! Please, mark the answer as correct (it's the green symbol) ;)

avatar image worldofcars · Feb 12, 2012 at 03:48 PM 1
Share

done;):):)

avatar image carter-carl30 · Apr 18, 2012 at 09:27 PM 0
Share

Hi, do you put this script on your player and the other one, on say a gui text on your main menu for load?

//Here, you are in the function that updates the last level reached //... level_index++; //Because you've reached the next level PlayerPrefs.SetInt("Last_Level", level_index);

avatar image BiG · Apr 19, 2012 at 09:57 AM 0
Share

Hi, I'm sorry but I don't understand if your comment is for me or for worldofcars. Indeed, your request isn't much clear to me: If you are asking where to put this code, I respond "wherever you want" (but I suggest a "neutral" object, like the camera), because it's independent by the player. Sorry if your comment was related to worldofcars for his project's implementation.

Show more comments

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

level loader script wont work 1 Answer

Can I put a Level as a property of a GameObject? 1 Answer

Application.LoadLevel not loading levels 1 Answer

Post-Build Custom Level Loading 2 Answers

Load a scene/level when enemy is close... 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