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
6
Question by burnumd · Nov 25, 2009 at 01:44 PM · guiscene

How can I allow a player to select from multiple scenes to load?

I'd like for players to be able to select from an arbitrary number of levels to load from some kind of hub (teleporter, map, etc) using a graphical menu. How can I achieve this effect?

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

4 Replies

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

Answer by burnumd · Nov 25, 2009 at 01:57 PM

In the simplest sense, you would set up an action to trigger the visibility of your menu (using OnTriggerEnter, OnMouseDown, or the like). The GUI code would look something like the following:

var availableLevels : String[]; var windowWidth : int = 200; var windowHeight : int = 200; private var showMenu : boolean = false;

function TriggerAction () { //Replace TriggerAction with your desired means of triggering the menu. showMenu = true; }

function OnGUI () { if (showMenu) { GUI.Window(0, Rect((Screen.width / 2) - (windowWidth / 2), (Screen.height / 2) - (windowHeight / 2), windowWidth, windowHeight), LevelSelect, "Select a level!"); //Creates a window with ID 0 in the center of the screen using the function LevelSelect with the title, "Select a level!" } }

function LevelSelect (id : int) { for (var levelName : String in availableLevels) { if (GUILayout.Button(levelName)) { Application.LoadLevel(levelName); } } if (GUILayout.Button("Cancel")) { //Gives the player the opportunity to back out of the menu. showMenu = false; } }

Comment
Add comment · Show 2 · 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 Jesus_Freak · Nov 02, 2010 at 07:41 PM 0
Share

okay, i'm using this script, and i voted you up because.... you're awesome and this script works, but all i did was change if(GUILayout.Button(levelName)) to ...("Level1")) and made copies of that for my six levels (still working on levels) and it works, when i click on the button, it sends me to my levels, but it seems that it makes copies of the selectable levels, like a list of levels repeating 1,2,3,4,5,6,1,2,...etc. for ever. can you help me?

avatar image burnumd · Nov 03, 2010 at 02:10 PM 0
Share

You shouldn't add copies of the Button. It automatically draws a button for every level name you put into availableLevels (that's what the for-loop is for).

avatar image
4

Answer by Jaap Kreijkamp · Nov 25, 2009 at 02:01 PM

Create C# class with name LoadLevelOnTrigger.cs and paste following code to it:

using UnityEngine; using System.Collections;

public class LoadLevelOnTrigger : MonoBehaviour {

 public string levelName;

 void OnTriggerEnter(Collider other) {
     if (other.gameObject.tag == "Player") {
         Application.LoadLevel(levelName);
     }
 }

}

Add script to object with collider set to trigger, set levelName property in inspector and walk into the collider (the player must have Tag "Player"). That's it.

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
avatar image
0

Answer by Murcho · Nov 25, 2009 at 01:50 PM

Add each scene you wish to include in the build settings for your game. Then however you are setting up selection of these levels, via a menu list or other wise, you launch the selected level using :

Application.LoadLevel("NameOfLevel");

There are a couple of other options for loading levels, but they either require Pro or are for multi segmented levels. You can find all the available functions here.

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
avatar image
0

Answer by SpiritWebb · Nov 25, 2009 at 03:09 PM

Not answering, just asking a question that involves the setup. burnumd wrote the code out, but what I am wanting to know with this question, is:

I have one jumpgate with locations (scenes): Vega & Alpha Centauri. Say I travel to A.C. now in that system, there is another gate, locations: Pegasus, Galnor & Bewlan. And in the previous gate: Sol.

Is this possible, and how would I set this up compared to the above code given by burnumd? Any help with this is greatly appreciated!

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 burnumd · Nov 25, 2009 at 05:09 PM 1
Share

Add the script above to individual jumpgates in the various scenes. From the inspector, you can specify which scenes are available from which gates.

avatar image SpiritWebb · Nov 25, 2009 at 05:22 PM 0
Share

Thanks. I will try this when I get home from work! And let you know if it worked, or done something wrong!

This works, and it will be a big improvement, to allow other interactions as well...

avatar image SpiritWebb · Nov 26, 2009 at 01:35 AM 0
Share

I tried. It doesn't really give me options, except for the scene number and I cant specify which systems I want linked.

When I tried to run, it tells me: Level couldn't be loaded because its not added to the build settings.

I know it is, cause I checked and made sure. Something is wrong, and I don't know what it is.

avatar image SpiritWebb · Nov 27, 2009 at 04:09 PM 0
Share

Never$$anonymous$$d, I got it working.

I learned that the available levels, when you change the number, it gives Element 0,1,2,etc. I didn't look at the fact I could click in the open space to specify a level name to make it work.

I had a blonde moment...

avatar image fireDude67 · Nov 17, 2010 at 03:34 AM 0
Share

So sad that I do not have enough rep for vote down yet... :(

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

No one has followed this question yet.

Related Questions

Loading a scene in game with a GUI 1 Answer

iOS Scroll Effect - SceneGUI Objects 0 Answers

Change to scene based on current scene 1 Answer

Display multiple scenes? 1 Answer

fade between scenes? 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