- Home /
How do i make night and day transitions
what script do i put on a point light to make it so day last 15 minutes and it slowly transitions into night and night last 1o minutes and slowly transitions into day?
Answer by Jessy · Jan 16, 2011 at 03:38 AM
Unity is not a "collection of scripts you attach". There are a few that come with it to do very common things, and that demonstrate how to script, but in general, you need to program things yourself. You can always search the Unify wiki for helpful scripts, but what you're talking about is not so general-purpose that I'd expect it to be there.
Here are the pages that I believe will be most helpful to you in learning what you need to learn to achieve your effect:
http://unity3d.com/support/documentation/ScriptReference/Light-intensity.html
http://unity3d.com/support/documentation/ScriptReference/Time-time.html
Answer by the_Simian · May 13, 2011 at 02:48 PM
There are a number of ways to do this yourself, but i should point out that some very sophisticated methods have been worked out by others.
For one example is Unisky: http://www.sixtimesnothing.com/unisky which does what you want and a lot more: procedural sky, weather, and atmospheric visual effects system.
in any case, heres a stab at a simple script to do what you want:
//set times here
var day_duration:float = (your time here);
//this makes a smooth intensity transition
var phi : float = Time.time / dayduration 2 Mathf.PI; var light_amplitude : float = Mathf.Cos( phi ) * 0.5 + 0.5;
//and this will make the light change.
light.intensity = light_amplitude;
then drag that badboy onto your light. , now it changes.
if you want somethign more sexy: here is a sunlight script out there in the community. http://unifycommunity.com/wiki/index.php?title=SunLight
and your skybox? here is some very good code for fading between two skyboxes: http://www.unifycommunity.com/wiki/index.php?title=SkyboxBlended
and if you don't want to build it all alone, or straight up just buy it... you can do something in between... buy a tutorial!!
http://forum.unity3d.com/threads/47951-Video-Tutorial-Day-amp-Night-Cycle
and voila!
that should cover all your bases, sir!
Answer by MrLolEthan · Oct 15, 2012 at 07:01 PM
var speed : float = 0.5;
//this is the speed your directional light rotates at
//adjust this to your liking
function Update() {
transform.Rotate(0,0,speed*Time.deltaTime);
}
What this script does is rotates the directional light (NEEDS TO BE DIRECTIONAL) and when it rotates it lowers the light. Adjust to your liking. Enjoy!
PS: You can copy and paste that script into a JavaScript file and attach the JavaScript file to the directional light.
Your answer
Follow this Question
Related Questions
Lighting only happening when the player get close. 4 Answers
Point Lights just dont work 3 Answers
lighting click help 3 Answers
Point light shadows broken? 0 Answers
How do I change a spot light to a point light by pressing a key? 1 Answer