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 nirovadya123 · Jun 18, 2019 at 01:01 PM · scenelistrandomrestartrestart game

Scenes don't repeat themselves after pressing a restart button

Hi, I made random levels that shouldn't repeat themselves after they are loaded. When the player fails and presses the restart button the scenes that were already in use don't repeat themselves again.

  private static List<int> remainingScenes = new List<int>() { 1, 2, 3, 4, };
 
 

     public void Update()
     {
         if (MainCamera.position.y >= 10.02)
         {
             startTimer = true;
         }
 
         if (startTimer)
         {
             timer -= 1.0f * Time.deltaTime;
             if (timer <= 0.0f && remainingScenes.Count > 0)
             {
                 startTimer = false;
                 int sceneIndex = Random.Range(0, remainingScenes.Count);
                 int scene = remainingScenes[sceneIndex];
                 remainingScenes.RemoveAt(sceneIndex);
                 SceneManager.LoadScene(scene);
 
                 
 
             }
         }
     }



Thank you :)

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 Hellium · Jun 18, 2019 at 02:08 PM 0
Share

Your question is not really clear.

When the user presses the Restart button, do you want the current scene to be reloaded or a random scene to be loaded (among the ones that have never been loaded before)

avatar image nirovadya123 Hellium · Jun 18, 2019 at 02:41 PM 0
Share

I want all the random scenes (the previously loaded scenes included) to show up again.

1 Reply

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

Answer by Hellium · Jun 18, 2019 at 02:56 PM

 private static List<int> remainingScenes;

 private void Awake()
 {
       if( remainingScenes == null )
           RebuildRemainingScenes();
 }

 
  public void Update()
  {
      if (MainCamera.position.y >= 10.02)
      {
          startTimer = true;
      }
 
      if (startTimer)
      {
          timer -= 1.0f * Time.deltaTime;
          if (timer <= 0.0f && remainingScenes.Count > 0)
          {
              startTimer = false;               
              LoadRemainingScene();
          }
      }
  }

  private void LoadRemainingScene()
  {
       int sceneIndex = Random.Range(0, remainingScenes.Count);
       int scene = remainingScenes[sceneIndex];
       remainingScenes.RemoveAt(sceneIndex);
       SceneManager.LoadScene(scene);  
  }

 // Call this function when the user restarts the game
 public void RebuildRemainingScenes()
 {
      if( remainingScenes == null )
          remainingScenes = new List<int>();
      remainingScenes.Clear();
      remainingScenes.AddRange( new int[]{ 1, 2, 3, 4, } );
 }





Comment
Add comment · Show 9 · 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 nirovadya123 · Jun 19, 2019 at 03:12 PM 0
Share

First of all, thank you for responding :) But that's not working. I tried this script, and connected the RebuildRemainingScenes to the OnClick command and nothing changed. I'll explain again: When the restart button is pressed the game restarts, but the scenes that were already loaded before the restart don't load again. I try to make them load themselves again after the restart button is pressed.

Thank you again.

avatar image Hellium nirovadya123 · Jun 19, 2019 at 04:51 PM 0
Share

I've edited a little bit the answer, I forgot to call a function in Rebuild

Does Debug.Log( remainingScenes.Count ); prints 4 in the LoadRemainingScene after the reload?

avatar image nirovadya123 Hellium · Jun 22, 2019 at 05:40 PM 0
Share

I added remainingScenes.clear to the Rebuild and added the debug. The console doesn't respond at all which means I guess that the amount of scenes after the restart is infinite. Do you have any idea what could be wrong? Because I can't really find a reason why the script doesn't work.

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.

Follow this Question

Answers Answers and Comments

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

Restarted scene not working properly 0 Answers

When animation finishes, restart the scene 0 Answers

can't save playerslist via stream in photon 1 Answer

Argument Out Of Range for random number selector 2 Answers

How to Restart game (Menu and Game are in same Scene)? 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