the sample code that microsoft supplies with their speech recognition unity example has asynchronous methods in a class that uses a button to call the voice record method and displays what the user says in a text ui element.
for someone who has not worked with async methods besides one week in my web dev class, it makes sense when it is working. “sure sure, call that method and it changes the text once it gathers what the user says in the microphone.” but what if i want to return a value instead of modifying a variable?
at first i didn’t think you could return a value, but then i found a video that did a pretty good job of explaining it abstractly and with an example. you can return tasks i guess, and then using await is how you can get the value out of that.
startasync calls voicerecord in my script, but the idea still holds. in my example, i’m trying to send the voice recognition script a string, compare it to what the user said, and return true or false based on that comparison. without await in the statement, i was getting an error that task<bool> could not be converted to bool.
it’s a bit confusing at first, but once i got it working it seemed fine, and can be called from any script without any button or text connected to it. now i just need to see if it works in our game.