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 meazant · Oct 30, 2011 at 01:25 AM · pauseloadlevelrestartquitmainmenu

Can't go back to the game scene from main menu for the second time

So, I have a button in main menu with this code

 var soundhover : AudioClip;
 var beep : AudioClip;
 var QuitButton : boolean = false;
 function OnMouseEnter(){
 audio.PlayOneShot(soundhover);
 }  function OnMouseUp(){
 audio.PlayOneShot(beep);
 yield new WaitForSeconds(0.35);
 if(QuitButton){
     Application.Quit();
 }
 else{
     Application.LoadLevel("tanktes");
 }
 } @script RequireComponent(AudioSource);

I can do the LoadLevel alright for the first time. And then I pause Ingame and go back to main menu by clicking a code. Here's the pause code :

     if(Input.GetButtonUp("Esc"))
 {
 doWindow0 = true;
 Screen.lockCursor = false;
 Screen.showCursor = true;
 Time.timeScale = 0;
 }

And here's the Back to menu button code:

     if(GUI.Button (Rect (10,30, 150,20), "Back to Menu"))
     Application.LoadLevel("StartMenu");

And I can go back to the main menu. But this time, the play game button AND the quit button are not working (tested it on the .exe file). The audio when the mouse is hovering plays fine so we can assume the script is working, but it's not going back to the game scene. What seems to be the cause of this? Helps appreciated.

Comment
Add comment · Show 4
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 Branislav · Oct 30, 2011 at 06:44 AM 0
Share

$$anonymous$$aybe you should put Time.timeScale back to 1.0

avatar image syclamoth · Oct 30, 2011 at 06:51 AM 0
Share

Does anyone know whether Update still happens if timeScale is set to 0? Someone should test that.

avatar image syclamoth · Oct 30, 2011 at 06:55 AM 0
Share

Just tested it- Yes, yes it does.

avatar image meazant · Oct 30, 2011 at 08:06 PM 0
Share

If I write :

 if(GUI.Button (Rect (10,30, 150,20), "Back to $$anonymous$$enu"))

     Time.timeScale = 1.0;

     Application.LoadLevel(level);

When I pause the game it suddenly go back to the main menu without even clicking the "Back to $$anonymous$$enu" button..

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by meazant · Oct 31, 2011 at 06:06 AM

Thank you for all of your help, I've found the problem. Yes, I need to turn back the Time.timeScale to 1 and also I have an error in the if statement. It lacks a {}. Newbish mistake and I am sorry for that. Nevertheless, always glad to get such speedy responses from Unity3D Answers people. Have a nice day :)

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 syclamoth · Oct 31, 2011 at 06:09 AM 0
Share

This is why I always put the brackets around if statements, even if they are only one line long. It gets you in the habit for when it's important.

avatar image
0

Answer by Computoguy · Oct 30, 2011 at 12:42 PM

Try adding an extra variable called something like 'levelToLoad' and make it a string variable. Then, replace any Application.loadLevel("levelname"); with levelToLoad. Everytime you click on the object which will load the level, it with an object in your scene, goto where it says Level To Load and put in the name of your level. That works for me.

*var levelToLoad : String;*
var soundhover : AudioClip;
var beep : AudioClip;
var QuitButton : boolean = false;
function OnMouseEnter(){
audio.PlayOneShot(soundhover);
}
function OnMouseUp(){
audio.PlayOneShot(beep);
yield new WaitForSeconds(0.35);
if(QuitButton){
Application.Quit();
}
else{
Application.LoadLevel(levelToLoad);
}
}
@script RequireComponent(AudioSource)
Hopefully that will work.

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 meazant · Oct 30, 2011 at 07:42 PM 0
Share

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

My GUITexture Script doesn't re-activate when reloading a level. 3 Answers

Main Menu in different scene - pause game 3 Answers

Pause at end of game 2 Answers

Proper way for Quit Application 2 Answers

Button on pause menu not showing up 0 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