1
\$\begingroup\$

I'm able to Lerp the color of a UI panel within the Update method. However I'd like to trigger behavior a single time when needed. If I put it in a method and call it it only changes for a brief time and doesn't fully complete. I could probably set a bool flag within the update method but that seems sloppy.

\$\endgroup\$
  • 1
    \$\begingroup\$ A tweener like DoTween or a coroutine will work. Have you tried either? \$\endgroup\$ – Sidar Mar 11 at 18:48
0
\$\begingroup\$

Using a Coroutine gives the desired effect.

IEnumerator ChangeColorTest()
    {
        for (var i = lerpDuration; i >= 0; i -= 0.1f)
        {
            UIPanel.color = Color.Lerp(startColor, endColor, Time.time / lerpDuration);

            yield return new WaitForSeconds(0.1f);
        }
    }

I'd like the color transition to be smoother but this might be how Coroutines work.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.