Camera background

New to Unity. Just want to animate the background fading from blue to red. using this code provided in unity docs but it doesnt work for me. i can see the camera background fading from blue to red in the inspector but it does not do it while playing

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
public Color color1 =;
public Color color2 =;
public float duration = 3.0F;

Camera MainCamera;

void Start()
    MainCamera = GetComponent<Camera>();
    MainCamera.clearFlags = CameraClearFlags.SolidColor;

void Update()
    float t = Mathf.PingPong(Time.time, duration) / duration;
    MainCamera.backgroundColor = Color.Lerp(color1, color2, t);


@okaybj This worked for me after I added the script as a component to the camera in my scene.

Yeah it seems to update when I click on something outside of unity then click back on the player window. Also works when I update stereo camera. Also works when I exported the apk and tested it on my phone. But just won’t update live in the play mode. Thanks for your response @vicarian