Why the code is not switching between the two colors using Color.Lerp ?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColors : MonoBehaviour
{
    public List<Transform> objectsToRotate = new List<Transform>();
    public float rotationSpeed;
    public Light[] lights;
    public Material material;

    // 0,31,191
    // 255,0,0

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < objectsToRotate.Count; i++)
        {
            objectsToRotate[i].Rotate(new Vector3(Time.deltaTime * rotationSpeed, 0, 0));
        }

        var c = Color.Lerp(new Color(255, 0, 0), new Color(0, 31, 191), 0.5f);
        material.SetColor("_EmissionColor", c);
    }
}

If I will take the part :

new Color(255, 0, 0)

and put it in the SetColor :

material.SetColor("_EmissionColor", new Color(255, 0, 0));

Then it will change the color but I want that it will lerp between the two colors all the time on half the way when rotating. So I tried this :

var c = Color.Lerp(new Color(255, 0, 0), new Color(0, 31, 191), 0.5f);

but then when I add the variable c to the SetColor the result is just white color.

The RBGA values of a Color instance must be between 0 and 1 instead of 0 and 255.
If you absolutely need to use values between 0 and 255, use Color32 instead.

This is almost working. The problem is that the time variable vlaue is never exactly 0 and never exactly 1.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColors : MonoBehaviour
{
    public List<Transform> objectsToRotate = new List<Transform>();
    public float rotationSpeed;
    public Light[] lights;
    public Material material;

    private float time = 0;

    // 0,31,191
    // 255,0,0

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < objectsToRotate.Count; i++)
        {
            objectsToRotate[i].Rotate(new Vector3(Time.deltaTime * rotationSpeed, 0, 0));
        }

        if (time >= 1f)
        {
            time -= Time.deltaTime * 0.1f;
        }

        if(time < 0.01f)
        {
            time += Time.deltaTime * 0.1f;
        }

        var c = Color.Lerp(new Color(255, 0, 0), new Color(0, 31, 191), time);
        material.SetColor("_EmissionColor", c);
    }
}

Not sure what you’re doing up there, but write it the way you want it to behave:

// go up to 1.0 and stop
if (time < 1.0f)
{
  time += Time.deltaTime * 0.1f;
  if (time >= 1.0f)
  {
    time = 1.0f;
  }
}

and same same for the decrement. Move towards the value, if you exceed it, return to it.

This is working just perfect as I wanted :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColors : MonoBehaviour
{
    public List<Transform> objectsToRotate = new List<Transform>();
    public float rotationSpeed;
    public Light[] lights;
    public Material material;
    public Vector3 targetAngle = new Vector3(-90f, 0f, 0f);

    private bool resetPos = false;
    private Vector3 currentAngle;

    // 0,31,191
    // 255,0,0

    // Start is called before the first frame update
    void Start()
    {
        currentAngle = objectsToRotate[0].transform.eulerAngles;

        StartCoroutine(SetTrue());
    }

    // Update is called once per frame
    void Update()
    {
        if(rotationSpeed == 0 && resetPos == false)
        {
            for (int i = 0; i < objectsToRotate.Count; i++)
            {
                currentAngle = new Vector3(
             Mathf.LerpAngle(currentAngle.x, targetAngle.x, Time.deltaTime), 0, 0);

                objectsToRotate[i].transform.eulerAngles = currentAngle;
            }

            resetPos = true;
        }
        else
        {
            resetPos = false;
        }

        for(int i = 0; i < objectsToRotate.Count; i++)
        {
            objectsToRotate[i].Rotate(new Vector3(Time.deltaTime * rotationSpeed, 0, 0));
        }
    }

    public void setHighlight(bool highlight)
    {
        if (highlight)
        {
            material.EnableKeyword("_EMISSION");
            material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
            material.SetColor("_EmissionColor", new Color(0, 31, 191));
        }
        else
        {
            material.EnableKeyword("_EMISSION");
            material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
            material.SetColor("_EmissionColor", new Color(255,0,0));
        }
    }

    IEnumerator SetTrue()
    {
        setHighlight(true);

        yield return new WaitForSeconds(0.5f);

        StartCoroutine(SetFalse());
    }

    IEnumerator SetFalse()
    {
        setHighlight(false);

        yield return new WaitForSeconds(0.5f);

        StartCoroutine(SetTrue());
    }
}