Hi everyone.
I have different object in my game. and they all need fadeout after dead. Not only the live, but also some structure need fade out too. So I put the function “Fadeout” and some other function in one file, called ChpLib.js. So I can call the function like this: ChpLib.Fadeout(gameObject, 2)
In “Fadeout”, I use “yield;”, but the script doesn’t work. Even some very simple script doesn’t work if there is “yield;” in it. For example :
static function Test(){
yield;
Debug.Log ("test Done");
}
I call this : ChpLib.Test(); it doesn’t work. But if i delete the yield, it works.
So, is my way call this kind of function wrong? or “yield” can’t work is static function? Is there any way like “#include ChpLib.js” or something else can make it work?
Thank you for reading my question. Waiting for your reply.
Any function containing a yield that is not a member of a MonoBehaviour (e.g. if it is static, or part of a custom class) needs some help to run correctly.
You will first need a reference to some MonoBehaviour that will at least live long enough to execute your function (or it might end prematurely). Then use StartCoroutine to start it: