Why when i put my color.lerp inside an if statement, the color doesn't interpolate anymore?

Outside the if statement, it’s working as expected, but inside the if statement it immediately changes color?

	void Start () {	
    	startTime = Time.time;
	}

    void Update () {
	    if (GetComponent<TextMesh> ().text.Equals ("1")) {
		    Camera.main.backgroundColor = Color.Lerp (normalColor, dangerColor, (Time.time - startTime));
	    }
}

Yep, this code has a problem. The problem is ‘startTime’. That is a Lerp’s third parameter needs to change value from 0.0 to 1.0 over time. If you execute the line of code you have here at any time after one second has passed, you will get an immediate change since ‘Time.time - startTime’ will be greater than 1.0. To fix, you can do something like this:

private TextMesh tm;
private float timer = 0.0f;
private float speed = 1.0f;

void Start () {    
	tm = GetComponent<TextMesh>();
}

void Update () {
	if (tm.text.Equals ("1")) {
		Camera.main.backgroundColor = Color.Lerp (normalColor, dangerColor, timer);
		timer += Time.deltaTime * speed;
	}
}

Note that the movement of the GetComponent() out of Update() and the use of ‘speed’ are not strictly necessary to solve your problem, but these changes are a bit better code.