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 Essential · Apr 22, 2013 at 10:11 PM · guimenupausepopup

Halt function midway until player presses 'OK' then continue

I'm constructing a tutorial function that runs through a series of events and will occasionally put an 'OK' popup on-screen that the player will confirm before the events continue.

What's a good way to pause this function's process while waiting for the player to 'OK' the popup?

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 jiteshvm · Apr 22, 2013 at 10:22 PM 0
Share

One way to do this is that you can have a singleton that maintains the global state of the game. It can have an enum with a Waiting state / Pause state. All other scripts in the project can register a callback function when the state changes.

1 Reply

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

Answer by proandrius · Apr 22, 2013 at 10:28 PM

You should use Coroutines for that, for example:

 private bool isOkay = false;

 void Start(){
     StartCoroutine(PopMessage());
 }
 
 IEnumerator PopMessage()
 {
  // PART 1: do something here
  if(isOkay==false) yield return; // function will wait while isOkay is false
  // PART 2: do something after isOkay is true
 }
 
 void OnGUI() {
 // when you click the button, function PopMessage will continue to PART 2
 if(GUI.Button(new Rect(0,0,100,50),"Set Okay to True")) {
 isOkay = true;
 }
Comment
Add comment · Show 6 · 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 whydoidoit · Apr 23, 2013 at 12:11 AM 2
Share

You meant:

 while(isOkay==false) yield return null;

Right?

avatar image proandrius · Apr 23, 2013 at 12:25 AM 0
Share

ah yyes, or yield return 0; it does not really matter at that point.

avatar image Essential · Apr 23, 2013 at 02:17 AM 0
Share

Hmm… I'm not well versed in C#. Can anyone translate what's happening into Javascript / English? :)

Won't declaring 'return' in the while loop just exit the function entirely? (I'm assu$$anonymous$$g yield return is just the same as return in JS)

avatar image proandrius · Apr 23, 2013 at 10:44 AM 1
Share

in javascript ins$$anonymous$$d of "yield return 0;" just write "yield;". And is$$anonymous$$d of void Start, void OnGUI, IEnumerator Pop$$anonymous$$essage, it just function Start, function OnGUI, function PoPmessage.

avatar image Essential · Apr 23, 2013 at 05:23 PM 0
Share

Thanks! Just tested it out and it's working nicely :)

As a tip (although maybe you were doing it for the benefit of this being a learning resource?) you can use while( !isOkay ) rather than while( isOkay == false ) for the same effect.

Show more comments

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

14 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

Related Questions

Paused Menu backdrop 1 Answer

How to pause a game with a GUI button 1 Answer

individual object menu 0 Answers

changing from mouse click to keys 0 Answers

Pause Menu - Loading & Quitting 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