Hello all
Is there a good way to implement a working (simple!) day/night cycle into my game? I don’t need anything complicated like a moon, just so that it gets dark for a minute or two, then automatically turns day again.
Also, is there a good way to make a weather system that randomizes weather between sun, rain, etc?
Thanks in advance!
You can make an IEnumerator Coroutine, which counts down the time of day/night and then sets a value to true.
Like this:
You have a Light Object, that we will be referencing and a bool that tells us if it is day or not.
This will probably not work if you copy paste it, but you can write it down and use the autocorrect function.
void Start()
{
StartCoroutine(DaylightCycle());
}
IEnumerator DaylightCycle()
{
isDay = false;
yield return new WaitForSeconds(please_insert_night_time_here);
isDay=true;
yield return new WaitForSeconds(please_insert_day_time_here);
StartCoroutine(DaylightCycle());
}
void Update()
{
//Here we will make the lights go out
if (isDay==false)
{
if (LightObject.GetComponent<Light>().intensity > 0)
{
LightObject.GetComponent<Light>().intensity -0.2f*Time.deltaTime;
}
}
if (isDay==true)
{
if (LightObject.GetComponent<Light>().intensity < 1)
{
LightObject.GetComponent<Light>().intensity +0.2f*Time.deltaTime;
}
}
}
This will probably throw a lot of errors, I just wrote it for you to explain how I would do it
hope it helps