Color.Lerp


(Sergey Ryabchenko) #1

Hello! Can I use Color Lerp for repeated changing of color of Ui element?Can Pls You make a sample how can I use Lerp?


(Leslie Young) #2

Lerp takes 3 parameters.

  1. is the start color
  2. is the color to reach
  3. is the end color

for 3.

  • 0 returns the color given at 1
  • 0.5 returns a color half way between 1 and 2
  • 1 returns the color given at 2

For field 3 you need a float variable to track where the transition is as. It must be initialised to 0 and then every update you add a few milliseconds that passed to it via the Delta Time Block. You can also multiply the Delta Time with some value to increase the speed. When this variable reaches 1 you need to subtract Delta Time rather than add to move in reverse. Easiest here is to keep a “direction” variable. Simply a float variable which is either 1 or -1 which you cna multiply with the timer variable when applying delta time.