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 Infamous911 · Jul 27, 2011 at 10:36 PM · timerpausequitendgamefinish

Pause at end of game

So I'm almost done with my Space Invaders style game, but I need a way to pause the game when you win (or lose) for a short amount of time, so that the player has time to see the text of "you win" or "you lose" before the application closes through Application.Quit(); Is there any way to do this without setting up some sort of complex timer thing?

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

2 Replies

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

Answer by vxssmatty · Jul 27, 2011 at 11:11 PM

I assume you call Application.Quit() from a coroutine... so...

 var endOfGamePause : int; //set wait time here
 
 function QuitGame () {
 
 yield new WaitForSeconds(endOfGamePause);
 Application.Quit();
 
 }
Comment
Add comment · Show 5 · 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 Infamous911 · Jul 28, 2011 at 12:24 AM 0
Share

I'm doing this in C# not JS so my 'function' is void, and it's giving me an error about not being able to return anything in a void function.

avatar image vxssmatty · Jul 28, 2011 at 01:03 AM 0
Share

You need to use an IEnumerator ins$$anonymous$$d of a void then.

http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html

Set it to C#

avatar image Infamous911 · Jul 28, 2011 at 03:53 AM 0
Share

Using this code: IEnumerator Awake() { yield return new WaitForSeconds(5.0F); }

I'm getting this error: Script error: Awake() can not be a coroutine.

avatar image YikYikHeiHei · Jul 28, 2011 at 04:50 AM 0
Share

You can not use Awake() to yield.

You should this

 void Awake()
 {
     ToDoSome();
 }

 IEnumerator ToDoSome()
 {
     yield return new WaitForSeconds(5.0F);
 }
avatar image Infamous911 · Jul 28, 2011 at 04:10 PM 0
Share

This works, thanks!

avatar image
0

Answer by YikYikHeiHei · Jul 27, 2011 at 11:38 PM

It can wait and show "you win" or "you lose".

Update

Change to C#

 using UnityEngine;
 using System.Collections;

 public class YourScriptName : MonoBehaviour
 {

     public int WaitASecondsAndQuit = 3;
     public bool isGameOver = false; //<-- this is set are game over?
     public bool isYouWin = false; //<-- this is set are the player win?

     void OnGUI ()
     {
         if (isGameOver)
         {
             if (isYouWin)
                 GUI.Label(new Rect(Screen.width/2,Screen.height/2,200,50),"You win");
             else
                 GUI.Label(new Rect(Screen.width/2,Screen.height/2,200,50),"You lose");
         }
     }

     IEnumerator QuitGame ()
     {
         isGameOver = true; //<-- And set other script if(isWinLose){ } to pause the game object not do any thing
         yield return new WaitForSeconds(WaitASecondsAndQuit);
         Application.Quit();
     }
 }
Comment
Add comment · Show 2 · 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 Infamous911 · Jul 28, 2011 at 12:31 AM 0
Share

But I'm doing this in C# and it is giving me the error: The body of SphereScript.OnTriggerEnter(UnityEngine.Collider)' cannot be an iterator block because void' is not an iterator interface type

avatar image YikYikHeiHei · Jul 28, 2011 at 01:31 AM 0
Share

I have to change this script to C#, please check this.

And my script have not OnTriggerEnter(UnityEngine.Collider), which script?

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

Timer with 5-6 rounds that spawns enemies then end game 0 Answers

Pause Menu upon Idle (timer & button issues C#) 0 Answers

Pause Time.time? 1 Answer

Button on pause menu not showing up 0 Answers

Pause for random amount of time at waypoint 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