- Home /
Question by
Hazzapizza · Dec 20, 2016 at 07:45 AM ·
daynight
How to Adjust Blender Value
Hey, I'm trying to create a Day/Night Cycle that uses shaders which can blend and I have been following BurgZergs tutorials but the blend option does not move when I press play. This is where the blend slider is and if you can help that would be appreciated. The script is also included:
using UnityEngine; using System.Collections;
public class GameTime : MonoBehaviour {
public Transform[] sun;
private Sun[] _sunscript;
public float dayCycleInMinutes = 1;
public float StartTime;
private float _dayCycleInSeconds;
private const float SECOND = 1;
private const float MINUTE = 60 * SECOND;
private const float HOUR = 60 * MINUTE;
private const float DAY = 24 * HOUR;
private const float DEGREES_PER_SECOND = 360 / DAY;
private float _degreeRotation;
private float _timeOfDay;
// Use this for initialization
void Start () {
_sunscript = new Sun[sun.Length];
for (int cnt = 0; cnt < sun.Length; cnt++) {
Sun temp = sun [cnt].GetComponent<Sun>();
if (temp == null) {
Debug.LogWarning ("Sun Script not found");
sun [cnt].gameObject.AddComponent<Sun>();
temp = sun [cnt].GetComponent<Sun>();
}
_sunscript [cnt] = temp;
}
_dayCycleInSeconds = dayCycleInMinutes * MINUTE;
RenderSettings.skybox.SetFloat("_Blend", temp);
_timeOfDay = 0;
_degreeRotation = DEGREES_PER_SECOND * DAY /_dayCycleInSeconds;
}
// Update is called once per frame
void Update () {
for(int cnt = 0; cnt < sun.Length; cnt++)
sun[cnt].Rotate (new Vector3(_degreeRotation, 0, 0) * Time.deltaTime);
_timeOfDay += Time.deltaTime;
if (_timeOfDay > _dayCycleInSeconds)
_timeOfDay -= _dayCycleInSeconds;
// Debug.LogError (_timeOfDay);
BlendSkyBox ();
}
private void BlendSkyBox(){
float temp = _timeOfDay / _dayCycleInSeconds * 2;
if (temp > 1)
temp = 1 - (temp - 1);
RenderSettings.skybox.SetFloat ("_Blend", temp);
// Debug.Log ("temp");
}
}
Thanks heaps :)
screen-shot-2016-12-20-at-20503-pm.png
(118.2 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612103054im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Blended skybox shader is messing with my lens flare 0 Answers
Billboarded Trees not lit? 1 Answer
Realtime daylight cycle? 1 Answer
Sun(light) rotation is not working 1 Answer
Using adaptive tonemapping along with day-night cycle 0 Answers