- Home /
Animation method/coroutine playable once or loop
I just started to implement a class with some static coroutines which take a sprite as parameter and some other values to make some basic animations (blink, color interpolation, translation, bump, etc.)
An example with the blink :
static public IEnumerator Blink(tk2dBaseSprite sprite, Color blinkColor, float blinkDuration, int cycles = 1)
{
while (cycles > 0)
{
var defaultColor = sprite.color;
sprite.color = blinkColor;
yield return new WaitForSeconds(blinkDuration);
sprite.color = defaultColor;
cycles--;
yield return new WaitForSeconds(blinkDuration);
}
cycles = 0;
}
Coroutines are very usefull in these cases for me because of the "WaitForSeconds" possibility.
My problem is that I would like a blink which also could possibly loop as a condition is true in an update() function :
void Update()
{
if(conditionForLooping)
{
blink()
}
}
But, obviously, it won't work with a coroutine. I thought about using a simple method and use bot Invoke() and InvokeRepeating() but I'd lose the "WaitForSeconds" and I'd have to stock a time variable in the class, which doesn't fit with a static method.
So, I feel stuck :) Could anybody help me ?
PS : sorry for my english, I hope my question is clear...