i trying to clean up the code i have now, so it doesn’t turn into one big mess, and currently i want to separate all functions that use yield (like fading,smoothing and those kind of things) into separate script, to make it static, because they are going to be used all over again from different scripts.
so, i made this script, named it YieldFunctions
function Update () {
}
static function Fade(col : Collider){
var t = 0.0;
while (t<1.0){
t+=Time.deltaTime *(1.0/0.5);
col.renderer.material.color.a=Mathf.Lerp(1.0,0.1,t);
yield;
}
}
i also made an empty game object, since i read that you need update to get yield work from static function. but now i dont know how to use it.
here is the example i tried (this piece of code is
located in other GO in update function):
var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),hit,100)){
YieldFunctions.Fade(hit.collider);
}
but sadly this doesnt work…how to use get this done…?