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 /
This question was closed Apr 14, 2019 at 01:15 AM by Marian10 for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Marian10 · Apr 13, 2019 at 03:27 PM · scenelast

Load end scene after set of randomized scenes

Hello there,

so as of now I got a starting stage, six levels, and the end stage. I randomized the levels and implemented a timer for when to change the scene. Now my problem is that everytime I run through the application and the last scene is loaded, the end stage does not follow. I want to achieve that the end stage is only loaded after the time has passed AND the last level is loaded. This is my code atm:

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System.Collections.Generic;
 
 public class LoadingAfterTime : MonoBehaviour
 {
     private static List<int> scenes = new List<int>() { 2, 3, 4, 5, 6 };

 [SerializeField]
 private float delayBeforeLoading = 10f;

 private float timeElapsed;


 private void Start()
 {
     timeElapsed += Time.deltaTime;
     if (scenes.Count <= 0)
     {
         Debug.LogWarning("No remaining scene to load");
         enabled = false;
     }
     if (scenes.Count <= 0 && timeElapsed > delayBeforeLoading)
     {
         SceneManager.LoadScene("TheEnd");
     }
 }
 private void Update()
 {
     timeElapsed += Time.deltaTime;
     if (timeElapsed > delayBeforeLoading)
     {
         int index = Random.Range(0, scenes.Count);
         int scene = scenes[index];
         scenes.RemoveAt(index);
         SceneManager.LoadScene(scene);
     }
   }
 }

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 mchts · Apr 13, 2019 at 03:37 PM 0
Share

Because you never reset timeElapsed. In Update when you meet timeElapsed > delayBeforeLoading condition reset the timer like timeElapsed=0; to prevent removal of all your scenes by scenes.RemoveAt(index); this line immediately.

avatar image Marian10 mchts · Apr 13, 2019 at 04:43 PM 0
Share

Sorry I guess my description could have been better. So the problem is mainly that is does not load at all, I achieved loading it but then it would only immediately load after the last scene startet ins$$anonymous$$d of at the end. If I use timeElapsed=0;scenes just wont load at all after the starting scene.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

122 People are following this question.

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

Related Questions

Load last scene/level 4 Answers

Active Canvas Button AdMob 0 Answers

What are the reason a scene don't reload the second time ? 0 Answers

Changing scenes by pressing a key press while being in a trigger 1 Answer

Why SceneManager.LoadScene (loadLevel) don't work? 3 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