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 Shire_ · Apr 19, 2016 at 06:54 PM · scene-loading

Scenes not loading in the correct order

Hi, I'm currently creating a basic unity 3D game and I have come across a problem with the scenes not loading in the correct order.

I have a main menu , 3 levels, a 'You win' and finally a 'You lose' scene (making a total of 6 scenes in that build order.)

However after clicking new game, it enters level one, upon completing level 1 it repeats level 1, then upon completing level 1 again it will successfully load level 2, and then upon completing level 2 it jumps straight to the 'You win' scene. I am new to unity and coding in general and feel i am missing something relatively obvious but i have been looking for hours for a solution and found nothing. Any help would be appreciated!

Here is the GameManager part involved:

using UnityEngine; using UnityEngine.SceneManagement; using System.Collections; public class GameManager2 : MonoBehaviour{

 public int currentScore;
 public int highscore;
 public static int currentLevel = 0;
   
 void Update()

 {  
     startTime -= Time.deltaTime;
     currentTime = string.Format("{0:0.0}", startTime);
     if (startTime <= 0)
     {
         startTime = 0;
         SceneManager.LoadScene(5);
     }
 }

   
 public void CompleteLevel()
 {
     if (currentLevel < 4)
     {  
         //this loads levels in sequence
         SceneManager.LoadScene(currentLevel += 1);

     
     }
     else {

         //this is the win settings
         SceneManager.LoadScene(4);
         print("You win");
     }
 } 


Here is the MainMenu part involved:

 public void LoadScene(string name)

{

     SceneManager.LoadScene(name); 

}

 public void QuitGame() { 

     Application.Quit();
 }

}

I was worried i had put them in the wrong order in the build settings so I removed all levels and placed them all back in in the correct order but that didn't help. As far as i can tell they are definitely in the correct order (but as i said i am new to unity).

thanks for reading and any help would be greatly appreciated :)

Comment
Add comment · Show 2
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 gjf · Apr 19, 2016 at 06:00 PM 0
Share

you've initialized your level number like this:

 public static int currentLevel = 0;

so, on the first load in CompletedLevel(), it'll become 1... not sure why level 3 wouldn't load. is that the only place you're increasing the counter?

try using named level names ins$$anonymous$$d... then the order won't be important either ;)

avatar image Shire_ gjf · Apr 20, 2016 at 10:12 AM 0
Share

Hey, thanks for the reply. in my player controller script i have this for completing the level.

 void OnTriggerEnter (Collider other)
 {
     if (other.transform.tag == "Goal")
     {
          manager.CompleteLevel();
     }   
 }

Could this issue be that i am only completing the level upon reaching the goal? do i need to set up a way to complete the level at the mainmenu to?

1 Reply

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

Answer by Shire_ · Apr 20, 2016 at 03:06 PM

FIXED!

finally found a fix in the end!

needed to use:

if (currentLevel < 4) { currentLevel = SceneManager.GetActiveScene().buildIndex+1; SceneManager.LoadScene(currentLevel); }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Audio and Scene Load Troubles 0 Answers

Game is Glitched After Reloading the Next Day 0 Answers

After reloading the scene twice one script doesn't work. 0 Answers

How do I load scene using scene manager Set Active Scene build index / ManagerScenes are not loading Build index 0 Answers

obbdownloader relevance 0 Answers


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