Reputation: 151
Is there any way to run a function and get the return value as a parameter for a function? Let me explain: I have a ton of functions lying around in my code which are just there for waiting a certain amount of seconds before something takes place. Since I only use them in one circumstance, I wanted to put them inside of my method that uses them somehow. (I'm using Unity3D.) Example:
public void SayHiAfterSeconds(float seconds) {
StartCoroutine(sayHiAfterSeconds(seconds));
}
IEnumerator sayHiCoroutine(float seconds) {
yield return new WaitForSeconds(seconds);
print("Hi.");
}
I want to put the sayHiCoroutine function inside of SayHiAfterSeconds. Something like:
public void SayHiAfterSeconds(float seconds) {
StartCoroutine(IEnumerator() {
yield return new WaitForSeconds(seconds);
print("Hi.");
});
}
Is that possible? Thanks.
Upvotes: 2
Views: 2091
Reputation: 125275
Short Answer: NO.
You can't put couroutine
function in another function but you can call it from another function. This has been asked before.
Upvotes: 1