• 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 Preston Halo · Mar 23, 2011 at 01:49 AM · levelmultipleselection

Level selection from main menu?

Hello. My problem is easy, but I don't know scripting very well, I have just now started reading on it.I've followed multiple searches with no results to what I'm looking for (ex: http://answers.unity3d.com/questions/46129/main-menu-creation-multiple-scenes-tutorial) I have my main menu gui, but it's set up to automatically load the "Test Map" after you hit start. I would like to be able to select a level (scene) I would like to play, hit play, and be at that level. My current script limits me only to the Testmap. Does anyone know of a good tutorial, or GUI script, that I can use so that I may select a level I would like to play? Thanks! ~Preston

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
3
Best Answer

Answer by Joshua · Mar 23, 2011 at 02:02 AM

If you go to File > Build Settings there is a list of scenes (levels) in your current build (game). Add all your scenes to this list and put them in the right order. The level you want to be loaded on startup should be level zero.

So in this case, put your main menu down as level zero. It will auto load.

Now in your script in the main menu use Application.LoadLevel(x) to love a scene, where x is the number you assigned to the scene in your build settings.


Example:

function OnGui () {
    if (GUILayout.Button("Level one")){
        Application.LoadLevel(1);
    }
    if (GUILayout.Button("Level two")){
        Application.LoadLevel(2);
    }


Edit for tutorial:

Learning GUI and leveloading and information you can retrieve from assigned levels

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 mcunha98 1 · Mar 23, 2011 at 02:18 AM

You too load using name of the level, for example:

Application.LoadLevel("LevelLoaderScreen");

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 Preston Halo · Mar 23, 2011 at 02:40 AM

This is my script based on what you've said. var newSkin : GUISkin; var mapTexture : Texture2D;

function theMapMenu() { //layout start GUI.BeginGroup(Rect(Screen.width / 2 - 200, 50, 400, 300));

//boxes GUI.Box(Rect(0, 0, 400, 300), ""); GUI.Box(Rect(96, 20, 200, 200), ""); GUI.Box(Rect(96, 222, 200, 20), "TestMap");

//map preview/icon GUI.Label(Rect(100, 20, 198, 198), mapTexture);

//buttons if(GUI.Button(Rect(15, 250, 180, 40), "start level")) { Application.LoadLevel(1); } if(GUI.Button(Rect(205, 250, 180, 40), "go back")) { var script = GetComponent("MainMenuScript"); script.enabled = true; var script2 = GetComponent("MapMenuScript"); script2.enabled = false; }

//layout end GUI.EndGroup();

}

function OnGUI () { //load GUI skin GUI.skin = newSkin;

//execute theMapMenu function
theMapMenu();

} Where can I add the other Application.LoadLevel groups, so that I may have multiple level selectors?

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 mubasherikram · Feb 19, 2015 at 11:40 AM

I think ou are facing problems to move across the scenes. For example if you flow is as following

main Menu -> Loading Scene -> respective level

you can store the value of selected scene in player pref and then use the value in loading scene to load the selected level.

For example in loading scene your line of code would be

Application.LoadLevel (PlayerPrefs.GetInt("levelToLoad" ,1 ));

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Make a Button For Every String in an Array of Level Names 1 Answer

simple android swipe controls for level selection? 1 Answer

locking levels based on new game 1 Answer

Destroy multiple objects user has selected? 1 Answer

Level Selection. Any Good Direction To Start? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges