- Home /
This question was
closed Nov 02, 2014 at 11:30 AM by
ExtremePowers for the following reason:
The question is answered, right answer was found and edited into the original question.
Question by
ExtremePowers · Nov 01, 2014 at 09:16 PM ·
skyboxblendnightday
Day/Night Skybox
I have modified a script I found, my problem with the script is that the Blend doesn't apply probably even though the value is right, its like the Material.SetFloat("_Blend", Blend) Doesn't run:
#pragma strict
var TOD : float;
public var sun : GameObject;
var NightAmbientLight : Color;
var DuskAmbientLight : Color;
var MorningAmbientLight : Color;
var MiddayAmbientLight : Color;
var SunNight : Color;
var SunDay : Color;
var NightSkyBox : Material;
var DaySkyBox : Material;
var NightBlendSkybox : Material;
var DayBlendSkybox : Material;
private var skybox : Skybox;
// Use this for initialization
function Start() {
skybox = GetComponent(Skybox);
sun = GameObject.Instantiate(sun, Vector3.zero, Quaternion.identity);
}
var DayLength = 24.0f;
var Hour = 0.0f;
var Blend : float;
function Update() {
Hour = Mathf.Clamp(Hour, 0, 1) == 1 ? 0 : Hour;
Hour += (Time.deltaTime / DayLength) / 60;
TOD = Hour * 24;
Blend = (Hour % (1.0f / 12.0f)) * 12.0f;
sun.GetComponent(Light).transform.localEulerAngles = new Vector3((Hour * 360) - 90, 0,0);
sun.GetComponent(Light).color = Color.Lerp(SunNight, SunDay, Hour);
if (TOD > 4 && TOD < 6) {
skybox.material = NightBlendSkybox;
skybox.material.SetFloat("_Blend", Blend);
RenderSettings.ambientLight = Color.Lerp(NightAmbientLight, MorningAmbientLight, Blend);
//it is Morning
} else if (TOD > 6 && TOD < 8) {
skybox.material = DaySkyBox;
skybox.material.SetFloat("_Blend", Blend);
RenderSettings.ambientLight = Color.Lerp(MorningAmbientLight, MiddayAmbientLight, Blend);
//it is Day
} else if (TOD > 18 && TOD < 20) {
skybox.material = DayBlendSkybox;
skybox.material.SetFloat("_Blend", Blend);
RenderSettings.ambientLight = Color.Lerp(MiddayAmbientLight, DuskAmbientLight, Blend);
//it is Dusk
} else if (TOD > 20 && TOD < 22) {
skybox.material = NightSkyBox;
skybox.material.SetFloat("_Blend", Blend);
RenderSettings.ambientLight = Color.Lerp(DuskAmbientLight, NightAmbientLight, Blend);
//it is Night
}
}
Comment
And what's the shader assigned to the skybox material? Does it have a _Blend property?
So is it working yet ? If so, you should close your question ^^ Also, you could drastically shorten your else/if statement to something shorter and more readable :
$$anonymous$$aterial sky$$anonymous$$at;
if (TOD > 4 && TOD < 6) { //it is $$anonymous$$orning
sky$$anonymous$$at = NightBlendSkybox;
} else if (TOD > 6 && TOD < 8) { //it is Day
sky$$anonymous$$at = DaySkyBox;
} else if (TOD > 18 && TOD < 20) { //it is Dusk
sky$$anonymous$$at = DayBlendSkybox;
} else if (TOD > 20 && TOD < 22) { //it is Night
sky$$anonymous$$at = NightSkyBox;
}
skybox.material = sky$$anonymous$$at;
skybox.material.SetFloat("_Blend", Blend);
RenderSettings.ambientLight = Color.Lerp(NightAmbientLight, $$anonymous$$orningAmbientLight, Blend);
Answer by ExtremePowers · Nov 01, 2014 at 10:39 PM
It does, but I fixed it. It was just some weird values. Edited the code above.