Here's the first class
public class Coroutiner extends MonoBehaviour
{
public function Coroutiner()
{
}
public function waiting(num: int)
{
yield WaitForSeconds(num);
}
}
And here's the second class (which contains the first class):
public Class ClassName
{
private var coroutinevar: Coroutiner;
//Other Variables
public function ConstructorName()
{
//Other Variables being initialized
coroutinevar= ClassName.AddComponent(Coroutiner);
Example();
}
public function Example()
{
Debug.Log("NO");
yield coroutinevar.waiting(5);
Debug.Log("YES");
}
//Other functions
}
Basically, when I tried to use the function in a statement checking to see if a keyboard key was pressed, it didn't work at all. If I extend monobehaviour with the second class, it works, but I get a warning, plus I would like to know how to do it outside of a class, especially since I've been trying to figure this out on my own for a while.
If I use the function within a normal script it works fine (the yield objectname.waiting(integer)), but using it within a class just causes that segment to be skipped entirely.
↧