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 /
avatar image
0
Question by riskaanisah · Dec 09, 2018 at 08:07 PM · randomscene-loadingscenesrandom.range

reload random scene

I have a code for random scenes, the scenes that I have are 10 randomized scenes, but when I reload the scene there is only one scene.

 public static int pointAdd;
     //menyimpan angka yang akan di random
     private List<int> myNiceNumbers = new List<int>();
     //nama scene yang akan tampil
     private List<string> sceneNames = new List<string>() { "GameDD10", "GameDD20", "GameDD30", "GameDD40"};
 
     private void Awake()
     {
         //objeknya berjalan terus walaupun ganti scene
         DontDestroyOnLoad(this.gameObject);
     }
 
     private void Start()
     {
         for (int i = 0; i < 5; i++)
         {
             myNiceNumbers.Add(i);
         }
     }
 
     public void NextScene()
     {
         if (myNiceNumbers.Count != 0)
         {
             int randomIndex = Random.Range(0, myNiceNumbers.Count);
             int randomNumber = myNiceNumbers[randomIndex];
 
             myNiceNumbers.RemoveAt(randomIndex);
 
             SceneManager.LoadScene(sceneNames[randomNumber]);
         }
         else
         {
             SceneManager.LoadScene("GameDDComplete");
         }
     }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vega4Life · Dec 09, 2018 at 08:26 PM

You have to also add your scenes to your build settings. Open up build settings and all the scenes that can be loaded will be at the top with a check mark. If they are not, open the scene, then add it.


  int index = Random.Range(0,10);
  SceneManager.LoadLevel(index);
  //SceneManager.LoadLevel(Random.Range(0, Application.levelCount));    // or this way


Try this instead


Also, you only have 4 sceneName strings, but you are creating 5 nice numbers. Some out of range action can occur.


 private List<string> sceneNames = new List<string>() { "GameDD10", "GameDD20", "GameDD30", "GameDD40"};     // Only 4 strings
  
      
      private void Start()
      {
          for (int i = 0; i < 5; i++)      // But you create 5 indexes
          {
              myNiceNumbers.Add(i);
          }
      }


Comment
Add comment · Show 5 · 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 riskaanisah · Dec 09, 2018 at 08:31 PM 0
Share

everything is already in the build setting, but it still doesn't work @Vega4Life

avatar image Vega4Life riskaanisah · Dec 09, 2018 at 08:45 PM 0
Share

I added some code for you to try as a test.

avatar image riskaanisah Vega4Life · Dec 09, 2018 at 09:01 PM 0
Share

then what about the code in each scene?

Show more comments
avatar image
0

Answer by riskaanisah · Dec 09, 2018 at 09:35 PM

I have 10 questions in different scenes. and I tried to make the scene display randomly. this has been successful using this code:

  public int pointsAddedForCorrectAnswer;
     //menyimpan angka yang akan di random
     private List<int> myNiceNumbers = new List<int>();
     //nama scene yang akan tampil
     private List<string> sceneNames = new List<string>()
     { "GameTiga1", "GameTiga2", "GameTiga3", "GameTiga4", "GameTiga5", "GameTiga6", "GameTiga7", "GameTiga8", "GameTiga9", "GameTiga10"};
 
     private void Awake()
     {
         //objeknya berjalan terus walaupun ganti scene
         DontDestroyOnLoad(this.gameObject);
     }
 
     private void Start()
     {
         for (int i = 0; i < 10; i++)
         {
             myNiceNumbers.Add(i);
         }
     }
 
     public void NextScene()
     {
         if (myNiceNumbers.Count != 0)
         {
             int randomIndex = Random.Range(0, myNiceNumbers.Count);
             int randomNumber = myNiceNumbers[randomIndex];
 
             myNiceNumbers.RemoveAt(randomIndex);
 
             SceneManager.LoadScene(sceneNames[randomNumber]);
         }
         else
         {
             SceneManager.LoadScene("RoundEndGameTiga");
         }
     }

and this is the code for each scene :

  public void NextQuestion()
     {
         GameObject.Find("RandomSceneGame").GetComponent<RandomScene>().NextScene();
         
     }
 
  public void Reload()
     {
         SceneManager.LoadScene("MenuDragDrop");
     }

but when I add the reload function, to repeat the game, it can't load all 10 scenes. but only 1 scene.

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

105 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

Related Questions

How to make Random.Range() step by a certain amount? 1 Answer

How can I do random choices 1 Answer

My next scene is not loading , 2 Answers

How to know what random number is chosen 2 Answers

An array of bools with random true and false elements 2 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