Unity DAY AND NIGHT In 6 Minutes!

preview_player
Показать описание
Let's make a simple day/night cycle controller in Unity3D!

Рекомендации по теме
Комментарии
Автор

If anyone's wondering why their game is super dark at night with this method, it's probably because your environment lighting source was set to skybox. I chose color and then this works great! I also added a fog density variable with thicker fog at night which is a nice touch.

lildgamedev
Автор

Dang if only I had seen this before the end of the ludem dare compo It would have really added some polish. Great channel btw.

cdd
Автор

Bruh this dude is like a coding GOD. I paused like 50 times trying to keep up lol

lildgamedev
Автор

I love the people that give code for free, don't stop coding!

odd-man
Автор

This looks so cool! I've my own Day/Night script that changes out directional lights, skyboxes, and fog colors. This looks so much smoother!

AvitheTiger
Автор

Awesome stuff! Just put it into my game and it's working great. I have a custom time system since my game is realtime but we wanted the days to be sped up, but thankfully I created enough pure functions for translating the timing that made this almost instant to pop in.

Orionhart
Автор

Nice work, Glynn! Simple, and certainly looks good enough to get the job done. :)

VRwithAndrew
Автор

Really great tutorial! Thanks for putting it together for us. I just found your channel and immediately subscribed ;-). Short, single-topic tutorials make the world a better place for everyone.

Palerider
Автор

I cant figure out how to get those multi colored gradients at 1:52.... ;___;

nevercanyoucant
Автор

Excellent, this is exactly what I was looking for, and it is simple to use. Thank you.

sadravin
Автор

Very nice tutorial, like how you structured the data and used validators, never kneew this was even possible! 😱 This is awesome!! 😁👍 🌜🌞

SnutiHQ
Автор

Straight to the point and a clear explanation, great tutorial

mathiasbruin
Автор

Thanks for this great video! Really easy to follow and does it's job wonderfully

joshvanwyk
Автор

This is a really good tutorial, thank you bro

theuniverse.
Автор

Thanks this works perfect for a open world project I'm developing

Zukomazi
Автор

Thank you for your help Mr. Glynn. God bless

capybaratech
Автор

amazing tutorial
all I changes was a I added a public float to change the day length in editor

Roxy_Rox
Автор

I took the script from the video, along with changes made by @cuckoo gaming below, and made some additional changes. This script now speeds up the late night hours, increases the directional light & softens the shadows toward noon. The rest of the class from the original script remains the same. (This was made using Unity 2019.4.19f1 LTS.)

public class LightingManager : MonoBehaviour
{
//Scene References
[SerializeField] private Light DirectionalLight;
[SerializeField] private LightingPreset Preset;
//Variables
[SerializeField, Range(0, 24)] private float TimeOfDay;
[SerializeField, Range(-10, 10)] private float speedMultiplier; // used to adjust the cycle time. Note that values < 0 will reverse it!
[SerializeField, Range(1, 10)] private float nightSpeed; // how much to speed up late-night hours
[SerializeField] private float maxIntensity = 1.5f;
private float baseIntensity = 0f;
[SerializeField] private float maxShadowStrength = 1f;
[SerializeField] private float minShadowStrength = 0.2f;
private float nightSpeedUpStart = 20f;
private float nightSpeedUpEnd = 4f;
private float dawn = 6f;
private float dusk = 18f;
private float noon = 12f;

private void Start()
{
// default values
speedMultiplier = 0.1f;
nightSpeed = 10.0f;
baseIntensity = maxIntensity / 2f;
}

private void Update()
{
if (Preset == null)
return;

if (Application.isPlaying)
{
//(Replace with a reference to the game time)
// speed up the time in dead of night
if (TimeOfDay > nightSpeedUpStart || TimeOfDay < nightSpeedUpEnd) // speed up the passage of night from 9pm to 3am
{
// TimeOfDay += Time.deltaTime * speedMultiplier * nightSpeed;
TimeOfDay += Time.deltaTime * nightSpeed;
}
else
{
TimeOfDay += Time.deltaTime * speedMultiplier;

// adjust light intensity and shadow softness for time of day
if (TimeOfDay >= dawn && TimeOfDay <= noon)
{
DirectionalLight.intensity = baseIntensity + (baseIntensity / (noon - dawn)) * (TimeOfDay - dawn);
= minShadowStrength + ((maxShadowStrength - minShadowStrength) / (noon - dawn)) * (TimeOfDay - dawn);
}
else if (TimeOfDay > noon && TimeOfDay <= dusk)
{
DirectionalLight.intensity = baseIntensity + (baseIntensity / (dusk - noon)) * (dusk - TimeOfDay);
= minShadowStrength + ((maxShadowStrength - minShadowStrength) / (dusk - noon)) * (dusk - TimeOfDay);
}
else
{
DirectionalLight.intensity = baseIntensity;
= minShadowStrength;

}
}
TimeOfDay %= 24; //Modulus to ensure always between 0-24
UpdateLighting(TimeOfDay / 24f);
}
else
{
UpdateLighting(TimeOfDay / 24f);
}
}

mikesellers
Автор

DUDE thank you so so so so so much you are life saver thanks for the tutorial thank you so much

samisalama
Автор

Great tutorial, thank you so much! :)

csab_csab
join shbcf.ru