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 /
This question was closed Oct 18, 2015 at 01:26 PM by Baste for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by sovan · Oct 13, 2015 at 11:54 AM · loadlevelload sceneload level

How do I load level after each unsuccesful level(player fails to complete the level)

Hi,

I am making a 2d game and going good. There are 8 levels in my game. The player has to complete each level to go to the next. I have a question to ask. If the player fails to complete any level the game will be over and a new scene named as "GameOver" will be displayed. Now in that scene I have two buttons "Restart" and "MainMenu". I want to restart the scene played just before the GameOver scene if user presses the "Restart" button. I tried with Application.Loadlevel(Application.loadedlevel) but it did not work.

Please help me with this. Thanks

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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Baste · Oct 13, 2015 at 12:17 PM

You'll have to store what level was played last in some way. Let's say you're loading the Game Over scene like this:

 void PlayerDied() {
      Application.LoadLevel("GameOver");
 }

Then the easiest thing would be to use PlayerPrefs to store the last scene played:

 void PlayerDied() {
     PlayerPrefs.SetInt("LastScene", Application.loadedLevel);
     Application.LoadLevel("GameOver");
 }

 //in the Game Over Scene:

 void RestartClicked() {
     int levelToLoad = PlayerPrefs.GetInt("LastScene");
     Application.LoadLevel(levelToLoad);
 }

An alternative is to make an object that's not destroyed when loading level (See DontDestroyOnLoad), and write the last level played to that.

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 sovan · Oct 18, 2015 at 11:57 AM 0
Share

Thanks @Baste it worked.

avatar image Baste sovan · Oct 18, 2015 at 01:26 PM 0
Share

No problem!

In the future, please reply to posts by adding a comment, not by adding a new answer. Answers are supposed to be answers, after all!

avatar image sovan Baste · Oct 18, 2015 at 01:52 PM 0
Share

sure. Thanks again.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I Set position when loading a new scene?,How do I set position to an object on load? 0 Answers

Loading new scene in unity 2D 0 Answers

Loading Particular UI from Different Scene 0 Answers

example of new way to load levels 1 Answer

How can I destroy a GameObject after a scene is loaded? 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