Day-night changing via rotating Directional Light

Hello,
I am trying to make rotating Directional Light for changing 2 skyboxes depending on transform.rotation.x value, but it doesn’t work. It is ignoring IF/ELSE statement. Anyone know how could I make it? Here is the script for better understanding:

#pragma strict

var daySpeed : float;
var DaySkybox : Material;
var NightSkybox : Material;

RenderSettings.skybox = NightSkybox;

function Start() {
    daySpeed = 0.1;
}

function Update() {

transform.Rotate(daySpeed, 0, 0);

if(transform.rotation.x > 0 && transform.rotation.x < 270) {
    RenderSettings.skybox = DaySkybox;
}

else{
    RenderSettings.skybox = NightSkybox;
}

}

Might I suggest not using a rotation? That will cause trees to stay ‘alight’. Here’s code for intensity switching.

//Duration of day
var duration : float= 500.0;//day is going to change ULTRA slowly

function Update() {
    // argument for cosine
    var phi : float = Time.time / duration * 2 * Mathf.PI;
   
     // get cosine and transform from -1..1 to 0..1 range
    var amplitude : float = Mathf.Cos( phi ) * 0.5 + 0.5;
    
    // set light color
    light.intensity = amplitude;
}

Then you could change your sky box based on intensity.