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 Yashiya Kiro · Mar 11, 2015 at 04:27 PM · scenecanvasmenuselection

Scene selection menu

I have been trying to create a game on Unity in these past few weeks. The game is to be for a school project and it's not gonna be anything big but since I'm quite a newbie on Unity and c# I've had my troubles, which were all mostly cleared until now...

I'm on the final phase of my project and all I need right now is a working menu that allows the user to choose from the 3 scenes in the game and start one of them.

What I did here was to create a Canvas with 3 buttons, each of them with the following scripts depending on the level desired:

 using UnityEngine;
 using System.Collections;
 
 public class loadlevelX : MonoBehaviour {
 
     public void LoadStage()  {
         Application.LoadLevel ("LvDesired");
     }
 }

I also tested with void Update() and void Start(), same result or no result alone, if necessary I'll explain in more detail.

My problem is that each time I start the scene (with all scenes already added to the project of course) I can choose any button but they all load the same level even if all the buttons have different scripts according to the level.

Can someone explain to me what am I doing wrong? Every single video I find is either a 1 level opening menu with just "Start Game" or "Exit" or is plain outdated (pre Unity 4.6)...

Comment
Add comment · Show 2
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 Mmmpies · Mar 11, 2015 at 04:41 PM 1
Share

Are you using the new 4.6 UI buttons or OnGUI buttons. If the new ones for a project this simple just create 3 public functions that each only load 1 level then link the onClick event to the right function for that button.

avatar image Yashiya Kiro · Mar 11, 2015 at 04:57 PM 0
Share

That worked! For future reference to anybody who might have a similar problem, what I did was basically change the code to:

 using UnityEngine;
 using System.Collections;
 
 public class loadlevel : $$anonymous$$onoBehaviour {
 
     void OnClick(){
                 LvXStart ();
         }
 
     public void LvXStart()  {
        Application.LoadLevel ("LvX");
     }
 }

and on the OnClick part on the button I added the button to be used and on the function the loadlevel.LvXStart()

That solved my problem, thank you very much!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Firedan1176 · Mar 11, 2015 at 05:19 PM

You could also try to create a public string on your script and type in the name of your level in the inspector. Then it's different for each button.

I'm confused as to why you'd use OnClick() when you can just use Unity's button system. On the button there should be an OnClick() section, and you don't need it in code. You could do something like this:

 void StartALevel(string levelName) {
 
 Application.LoadLevel(levelName);
 
 }

And in the inspector:

Button Inspector

In the OnClick() section, you can click the +, drag the gameObject with the script into the empty field, then use the dropdown list to select your LoadLevel script, and then the StartALevel() function. There will be a space where you can then enter in a string (which is why my example says string levelName), which can be different for each button.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UI doesn't render after scene reload. 0 Answers

Object reference not set to an instance of an object. 1 Answer

Does unity have a feature that lets you change something in one scene from a completely different scene? 1 Answer

How do I switch scenes by obtain a children ui canvas text 0 Answers

How Can I save my values with Toggles in UI canvas 4.6 through scenes? 3 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