Lerp on Timer to Change Color C#
Hi guys, I'm trying to change the color of my character over the time of the game.
When the game start there are a timer of 30 secs and i want to my character color (he's base color is blue) to turn red over the time come to 0, some objects can add or make loose time (10 secs).
I have trouble with this line of code :
  _newColor = Color.Lerp(_myColor.color, _endTimerColor, Time.deltaTime * (_maxTime / _currentTime));
 
               I know it's wrong but it's just a example. How can i make it work ?
Here is my code :
     // TIMER VARIABLES
     public float _maxTime = 30f;
     public float _delay = 1f;
 
     float _startTime;
     float _currentTime;
 
     //COLOR VARIABLES
     public Material _myColor;
 
     Color _baseColor = Color.blue;
     Color _endTimerColor = Color.red;
     Color _newColor;
 
     void Start () {
 
         _startTime = Time.time;
         _currentTime = _maxTime;
 
         _myColor.color = _baseColor;
     }
 
     void Update () {
 
         // TIMER
         if (_currentTime > 0) {
             
             float _difference = Time.time - _startTime;
 
             if (_difference > _delay) {
     
                 _currentTime -= 1;
                 _startTime = Time.time;
 
                 Debug.Log (_currentTime);
             }
         }
 
         //CHANGE COLOR OVER TIMER
         _newColor = Color.Lerp(_myColor.color, _endTimerColor, Time.deltaTime * (_maxTime / _currentTime));
         _myColor.color = _newColor;
         _myColor.SetColor ("_EmissionColor", _newColor);
     }
 
              
               Comment
              
 
               
              Your answer