Hi, I’m planning an educational purpose a text adventure.
The actions are chosen either by clicking on the buttons, or by keyboard keys.
As for the Onclick Button, it works fine.
What I would like to change is the recall by keyboard. Currently it “waiting” in the Update that some key (Example : WASD) is pressed.
Is it possible to have a method call, where the code stops in this method, until it calls a new method to continue?
I was thinking of a coroutines, but I’m not sure how they work. Are there any examples or tutorials that can come up to me for my case?
For a button based game, it would make much more sense to tie the methods to the button presses. Here’s an old Brackey’s video which shows how to do that.
You may be looking for something like I’ve shown over here where I dynamically subscribe to one or multiple buttons in order to wait for a click inside a coroutine. However, currently that doesn’t mix that well with also waiting for a key press at the same time. Technically that could be done with some additional custom yield instructions to “combine” several yield instructions logically (like AND or OR). Though I’m not sure that would make the concept much simpler. While I’m also a fan of having things only active when needed and coroutines are great to model sequential dialogs and logic, everything has its limits. So it’s possible, but requires some additional boilerplate and helper classes / coroutines to get it working.