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 vooj12 · Dec 11, 2013 at 11:18 PM · randommappingselect

Random Map Selection

I have created some scenes that each contain different maps. I don't want people to be able to select scenes, but unity to randomly pick a scene to load.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Ryuuzoji · Dec 11, 2013 at 11:34 PM

Currently on my laptop and don't have unity with me, but you should be able to do this:

Make sure that all your random scenes are after each other in the build. Then the following code should do the trick:

 #pragma strict
 var lowest :int;
 var highest :int;
 var number : int;
 
 function randomLevel () {
    number = Mathf.Floor(Random.Range(lowest,highest+1));
    Application.LoadLevel(number);
    
 }

Just set the lowest and highst to the numbers where your list starts and ends.

Hope it's useful

Comment
Add comment · Show 4 · 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 robertbu · Dec 11, 2013 at 11:37 PM 1
Share

@Ryuuzoji - you don't need the $$anonymous$$athf.Floor(). Random.Range() with integers, returns an integer. Nice catch on the +1.

@vooj12 - @Ryuuzoji's solutions is the simplest. As an alternate, you can create an array of scene names and then use Random.Range() into the array to pick one:

 String st = names[Random.Range(0, names.Length)];
 Application.LoadLevel(st);

 
avatar image Ryuuzoji · Dec 11, 2013 at 11:57 PM 0
Share

Ah, thought it returned a float? Haven't used it much though, and just checked the documentation briefly. I should really get Unity on my laptop...

avatar image flaviusxvii · Dec 11, 2013 at 11:59 PM 0
Share

If you call it with ints you get an int.. floats you get a float.

avatar image Ryuuzoji · Dec 12, 2013 at 12:24 AM 0
Share

That's pretty useful. Good to know.

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

C# array equal to another array minus one entry. 1 Answer

AI random target 2 Answers

Mapping Cube to Sphere - Using 64 planes as a cube "side" 1 Answer

Selecting Random Object and Setting Variable to True 2 Answers

Random level select 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