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 RKM_91 · Apr 18, 2015 at 10:52 PM · gameover

How to return to Main Menu scene via buttons on the Gameover scene?

Hello Unity Answers,

I am trying to return to the Mainmenu scene once the game has finished. I have created a Mainmenu & gameover scene.

The gameover scene is made up of UI text which I have added a Button script to make them clickable buttons. I want the player to click PLAY AGAIN & EXIT to return to the main menu or exit the game.

All help and suggestions welcome.

alt text

Gameover scene alt text

Main menu scene alt text

 using System;
 using System.Collections.Generic;
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Gameover : MonoBehaviour {
 
     private int count;
     public Text countText;
     public Button PlayAgainText;
     public Button exitText;
     public void UIActions (string loadActions)
 
     {
         if (loadActions == "Play Again")
         {
             Application.LoadLevel ("3");
         }
     }
 
 
     void Start () 
     
     {
         DontDestroyOnLoad (gameObject);
         count = 0;
         SetCountText ();
         PlayAgainText = PlayAgainText;
         exitText = exitText;
 
         if (GUI.Button (new Rect (20, 100, 100, 30), "1976")) 
 
 
         { 
             Destroy (this.gameObject);
             count = count = 0;
             SetCountText ();
         }
 
     }
 
     
     void SetCountText()
     {
         countText.text = "Score: " + ValuesHolder.answersCount.ToString();
         ValuesHolder.answersCount++;
 
     }
 
 
     public void StartLevel()
     {
     Application.LoadLevel (3);
     }
 
     public void ExitGame()
     {
     Application.Quit ();
     }
 }
 
 
 
 
 
 
 
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
Best Answer

Answer by nightbane30 · Apr 19, 2015 at 02:13 AM

You'll want to create a public method with an Application.LoadLevel in it, then assign it in the editor to your button. How to do this:

 //make sure you have some kind of public method in your script like this
 
 public void LoadMainMenu(){
 
 Application.LoadLevel("NAME-OF-MAINMENU-SCENE-REPLACES-THIS-TEXT");
 
 }

Next, go to the button (I'm assuming the one that says Play Again) and click on it. View it in the inspector and go to the component called "Button (Script)". From there, near the bottom of the component, click the small + icon in the box that's titled "On Click()". Then, drag and drop your gameobject with the script to load the main menu attached to it into the empty field on the bottom-left. After that, click on the button diagonally right of that titled "No Function". Navigate to the dropdown for the name of your script, and from there choose the name of the public method you created (In this case the one I wrote is called "LoadMainMenu()"). Then, hit play and it should be all good to go! Sorry if some of that was unclear. I can try and take annotated screenshots if you still need help with the problem.

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 RKM_91 · Apr 19, 2015 at 07:45 AM 0
Share

Thank you so much, very clear instructions. :)

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

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

Related Questions

How to Create game Over Scene in this Scripts 0 Answers

How do I add a Game Over text to my timer? 1 Answer

On death show onGUI and wait 5 seconds to load next level 2 Answers

End game after 120 seconds HELP 1 Answer

Stop Camera Following Player When Descending 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