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 Suzuka91 · Feb 03, 2017 at 09:28 PM · inputcoroutinesinput.getkey

Checking Input on 2 different coroutines at the same time

Hi, this is my problem: I have 2 different coroutines that are "waiting" to check when the player presses the keys "1" or "2" of the keyboard. Is a Conversation system, so, the ConversationController is waiting for the keys 1 or 2 to continue the next string of the dialogue, while other script containing the dialogue, is waiting for the player to press 1 or 2 in order to choose the option to say.

I found the problem that the player must press 2 times the key; To choose the option and to continue the dialogue.

The issue could be solved by using Input.GetKeyDown () on the ConversationController, and Input.GetKeyUp () in the other script.

But I do not really like that solution. I want to understand why 2 cueroutines can not check at the same time Input.GetKeyDown

Thanks for reading and helping :)

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 PizzaPie · Feb 04, 2017 at 01:34 PM 0
Share

Coroutines does not run simultaneously meaning that they run on the $$anonymous$$ain thread. The difference from normal functions is that they ll return control to the caller when a yield return instruction encountered and re gain control after the instructed time or codition has passed. By putting the checks on the Update() of the active dialogue it will only check while the dialogue is Active. There is no performance issue and might occupy less memmory from instatiating 2 coroutines (that depends on several factors though).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IvanDrake · Feb 04, 2017 at 12:01 AM

Why are you using two Coroutines? Why not use the Update function? You shouldn't need Coroutines to "wait" for input.

 if ( Input  "1"){
      // Select option 1
      // Advance dialog
 } else if ( Input "2"){
      // Select option 2
      // Advance dialog
 }

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 Suzuka91 · Feb 04, 2017 at 12:51 AM 0
Share

Hi, thanks for your answer

I'm using coroutines because it's more efficient than checking all the time in the update function. I just need to wait for input on certain moments, when there is a dialogue with options, so checking every frame is not necessary.

avatar image IvanDrake · Feb 04, 2017 at 12:42 PM 0
Share

Admittedly, I'm not a program$$anonymous$$g expert, but in my experience, using the Update is typically less processor heavy than using multiple, simultaneous coroutines.

If you don't need it checking for input every time, then use a Boolean:

 if(ready){
 if(Input "1")  ... etc.

You can always start your coroutines from inside the If statement, if necessary.

Of course, I've never written a dialog tree before, so I'm not entirely sure how you're script is working.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input management with coroutines in a fighting game. 0 Answers

Unable to catch KeyCode.LeftShift Down AND Up 5 Answers

Input keycode string not working 2 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Detecting left and right being pressed at the same time. 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