• Unity
  • Transitioning from one color to another progressively

  • Modifié
Related Discussions
...

Hey! Sorry to bother you!

I've been searching threads about this but could not find anyone having the same trouble.
My question: How could I transition from one slot color to another progressively via c# (I'm using Unity).

I usually use skeleton.FindSlot().SetColor() but this method does not work with a lerp.
Is there another way to access slot color? Or how should I approach it?

Thanks for your attention! 🙂

The typical way to do it would be to write code that sets the color each frame. Usually you have a variable that is a percentage from 0 to 1, then you multiply the color parts, eg:

Color color, start, end;
currentTime += delta;
float percent = min(currentTime / duration, 1);
color.r = start.r + (end.r - start.r) * percent;
color.g = start.g + (end.g - start.g) * percent;
color.b = start.b + (end.b - start.b) * percent;
color.a = start.a + (end.a - start.a) * percent;

Alternatively, you could create an animation that does the color changes you want, then play that using AnimationState.

Oh! that's what I was looking for! 🙂 Thanks a lot!