Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 mmangual_83 · Feb 04, 2014 at 07:38 PM · c#scenecamera viewport

Removing scenes with set conditions

I have this task where I have to set up 3 cameras for each of my scenes (a total of 10 scenes). Next, I must somehow make them load randomly every time the user starts the game. So, ideally, the user starts from a different viewport each time. In addition I have to keep them in a list.

I went ahead and did that:

  1. created the camera list

  2. Initialized the 3 cameras that I am going to use

  3. Stored those 3 cameras into the camera list

(I hope you are still following me so far)

In addition to the camera task I have to set up a class where I have to store each of my scenes into a list and then load the scenes randomly. Thus, every time the user starts the program a new scene is loaded.

I went ahead and did that:

In my global variable region: public static List scenes;

In my Start() method: scenes = new List(Enumerable.Range(1, MAX)); // This creates a list with values from 1 to MAX

I have MAX set up to 9 since I have 10 scenes created.

Next, I handle each scene being loaded in this method which I am treating as an event. Forgive my hacky approach:

 private void OnLoadNextLevelHandler()
     {
         if (scenes.Count > 0)
         {
             int randomIndex = Random.Range(0, scenes.Count);            
             int level = scenes[randomIndex];
             
                 Application.LoadLevel(level);
                 scenes.RemoveAt(randomIndex); //once I am done with the scene, remove it
         }
     }

It works like a charm! Every scene is being randomly picked with a random camera each time and it looks great!

However, as we enter into the new phase of our student project some new features have been requested and it is here where I am having issues:

I want to be able to load each scene randomly and start from a different camera angle each time (like before) but this time I have to be able to go back to the same scene and load one of the randomly selected viewport that remain in the camera list.

I have to be able to keep going back to that scene while there are viewports remaining. When a scene has run out of cameras then that scene is removed from the list. Once all scenes have been removed from the list then a window pops up congratulating the user for completing the task and there is a button that, when clicked, closes the application.

The only thing I have changed is add a condition when the program loads a level. Apologies for taking such a hacky approach:

 //Making sure that all "viewports" list from each scenes are not empty. Basically I want to be able to load the same scene more than once if there are any cameras left in that scene...  
             if(Scene1_CameraHandler.viewPorts.Count > 0 || Scene2_CameraHandler.viewPorts.Count > 0 || Scene3_CameraHandler.viewPorts.Count > 0 ||
                Scene4_CameraHandler.viewPorts.Count > 0 || Scene5_CameraHandler.viewPorts.Count > 0 || Scene6_CameraHandler.viewPorts.Count > 0 ||
 Scene7_CameraHandler.viewPorts.Count > 0 || Scene8_CameraHandler.viewPorts.Count > 0 ||
                 Scene9_CameraHandler.viewPorts.Count || Scene10_CameraHandler.viewPorts.Count)
             {
                 Application.LoadLevel(level);
             }
             else
                 scenes.RemoveAt(randomIndex); // ... if there are no more cameras then remove the level from the list            
         }

To remove the current viewport I put this code at the end of each scene when the user clicks the "Done" button to load the next random scene:

 Scene1_CameraHandler.viewPorts.Remove(Scene1_CameraHandler.viewPorts[Scene1_CameraHandler.randomCameraSelectorIndex]);

This loads the level and the viewports just fine (as it did before) but now when it tries to go to a previous scene the program just stops and gives me an error stating: ArgumentOutOfRangeException: Argument is out of range.

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

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

IS it possible to load the whole game (and all scenes) at startup to avoid scene change delay? 1 Answer

Distribute terrain in zones 3 Answers

Streamed scenes in standalone build 0 Answers

Multiple Cars not working 1 Answer

A node in a childnode? 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