Skip to main content
1 of 2
Taco
  • 326
  • 1
  • 17

You're setting the color of a Renderer material, not that of a light.

public class gradient : MonoBehaviour
{
    public Gradient myGradient;
    public float strobeDuration = 2f;

    public void Update()
    {
        float t = Mathf.PingPong(Time.time / strobeDuration, 1f);
        GetComponent<Renderer>().material.color = myGradient.Evaluate(t);

        // Attempt to get a light and set its color.
        if (TryGetComponent(out Light light))
            light.color = myGradient.Evaluate(t);
    }
}

I also recommend using TryGetComponent for your Renderer too as the object may not have a renderer, in which case you'll get a NullReferenceException with the way your code is written when trying to access .material.color.

Taco
  • 326
  • 1
  • 17