- Home /
Increase Light Intensity in Coroutine
I am trying to increase a light to get a camera flash effect with a coroutine, but for some reason I cannot increment the light's intensity. This is what I have so far:
IEnumerator CameraFlash( tk2dAnimatedSprite sprite ){
GameObject flare = GameObject.Find( "CameraFlare" );
flare.light.intensity = 0;
float steps = (float) (3 / 9);
while(flare.light.intensity < 3){
yield return null;
flare.light.intensity = steps;
steps+=steps;
}
}
Comment
Answer by robertbu · Feb 05, 2013 at 05:21 AM
enter code here
The problem is with this line:
float steps = (float) (3 / 9);
You don't cast your values to a float until after the integer division, so 3 / 9 will be 0 and your loop will never complete.
Change the line to :
float steps = 3.0f / 9.0f;