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
  • 1
    \$\begingroup\$ A tweener like DoTween or a coroutine will work. Have you tried either? \$\endgroup\$ Commented Mar 11, 2019 at 18:48

1 Answer 1

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\$
1
  • 5
    \$\begingroup\$ "this might be how Coroutines work" nope. You're waiting a tenth of a second (ie. 3-6 frames) between iterations instead of updating the colour every frame (which you can do with yield return null). You're also using the wrong calculation of the blend parameter to adjust for time. \$\endgroup\$ Commented Mar 11, 2019 at 19:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.