c# - Slowly fade in the opacity of a particle system -
i trying write code slowly fades in opacity of particles when player reaches @ position.
the particle alpha value changed when player reaches postion doesn't fade, changes.
i new programming wondering if missing blatantly obvious. thanks!
public class increasefog : monobehaviour { renderer rend; gameobject character; float valtobelerpedfrom = 9f; float tparam = 0f; float speed = 0.01f; float characterposition; color c; void start () { rend = getcomponent<renderer>(); character = gameobject.find("character"); } void update() { characterposition = character.transform.position.x; if(characterposition >= 190f) { startcoroutine(increasefog()); } } ienumerator increasefog() { tparam = 0f; while (tparam < 1) { tparam += time.deltatime; valtobelerpedfrom = mathf.lerp(0f, 0.9f, tparam); c = rend.material.getcolor("_tintcolor"); c.a = (valtobelerpedfrom); rend.material.setcolor("_tintcolor", c); } rend.material.setcolor("_tintcolor", c); yield return valtobelerpedfrom; } }
it's because have while loop in it...you need execute once each frame. stands now, code won't complete until alpha 0.9, never see transition.
Comments
Post a Comment