Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RadioR4Y · Feb 03, 2017 at 09:34 PM · scripting problemmenuquit

How do I make a Quit To Menu script?

I am making a drag and drop game for a school project, and the script I use was taken from the Unity tutorial How to Make a Menu, here is the script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 public class QuitToMenu : MonoBehaviour
 {
 
     public void LoadByIndex(int sceneIndex)
     {
         SceneManager.LoadScene(0);
     }
 }

Whenever I press the Start button on my Menu then go to the game scene and click the Quit To Menu button it does not quit for me. It does not give me any errors using the script, so I do not know why it isn't working.

Comment
Add comment · Show 1
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 FortisVenaliter · Feb 03, 2017 at 10:00 PM 0
Share

Did you hook up your button's onclick event to that function?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Loui_Studios · Feb 03, 2017 at 10:02 PM

Firstly, set the value of the scene you are loading to 'sceneindex' instead of 0 to make things easier. Now when you want to load a scene, use LoadByIndex().

  public void LoadByIndex(int sceneIndex)
  {
      SceneManager.LoadScene(sceneindex);
  }

Now make sure that the menu scene has the index of '0' before loading.

alt text If done correctly, calling LoadByIndex(0) will load the menu scene.

Otherwise, double check your 'quit to menu' button and make sure that you are calling the LoadByIndex funtion, and that the value you are calling is '0'.

Let me know if this works for you!


capture.png (40.0 kB)
Comment
Add comment · Show 1 · 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 RadioR4Y · Feb 07, 2017 at 09:11 PM 0
Share

Sorry, but the script does not seem to work. Whenever i replace the sceneIndex to 0 it gives me errors. Sorry again, but I forgot to mention that I use Unity 5.3.3. This may be why it gives me errors.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Touch a box collider, quit the game. (2D) 1 Answer

Menu not working properly 1 Answer

Assets > Create > C# Script missing? 1 Answer

Pause menu not working 1 Answer

need help with armor customization 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