• 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 15, 2015 at 07:18 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;
 
 
     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 ExitPress()
     {
         
         PlayagainText.enabled = true;
         exitText.enabled = true;
         Application.LoadLevel("Main Menu");
 
     }
 
     public void StartLevel()
     {
         Application.LoadLevel (1);
     }
     
     public void ExitGame()
     {
         Application.Quit ();
     }
 }
 
 

Comment
Add comment · Show 6
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 VoidScreamer · Apr 15, 2015 at 08:18 PM 0
Share

What's the problem exactly ? which version of unity are you using? 4.6 ?

avatar image RKM_91 · Apr 15, 2015 at 08:22 PM 0
Share

The problem is when I reach the end of the game and click either PLAY AGAIN OR EXIT, it doesn't go back to the main menu scene. Yes using unity 4.6.

avatar image Guppie1337 · Apr 15, 2015 at 08:48 PM 0
Share

Are you sure the scene is added to the build list?

avatar image RKM_91 · Apr 15, 2015 at 08:58 PM 0
Share

Yes

$$anonymous$$ain $$anonymous$$enu is 0, Game is 1, GameOver is 2.

avatar image Guppie1337 · Apr 15, 2015 at 09:20 PM 0
Share

You can try using a condition and pass a value from the click to a function in the script.

 public void UIActions (string loadActions)
 {
     if (loadActions == "Play Again")
     {
         Application.LoadLevel ("$$anonymous$$ain $$anonymous$$enu");
     }
 }

Just assign the function for the button to use via the inspector and the option to add "Play Again" string will be available.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tim Jansen · Apr 15, 2015 at 08:02 PM

If you want to use the legacy UI, you can probably do something like:

  void OnGUI()
  {
 
     if (GUI.Button (new Rect(x, y , width, height), "PLAY AGAIN")
     {
         StartLevel()
     }
         
     if (GUI.Button (new Rect(x, y , width, height), "EXIT")
     {
         ExitGame()
     }
 }

If you want to use the new Unity UI (I think from unity 4.6 and upwards) you might want to take a look at this: http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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 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