meta data for this page
Create a Nightlight
This tutorial will explain how you can create a nightlight:
First we have to open the prefab. If you do not know how you can create a prefab, we can recommend the tutorial create a prefab .
Select your prefab in the project window and open the prefab.
Now select the object in the inspector at the left side:
Press Strg+C
and then paste it two times with strg+v
We will need this object 2 times:
- One time for the day
- 2nd time for the night
Now select the object at the top and remove the Mesh Filter
and Mesh Renderer
with a right click
on the component and remove component
.
Now it should look like this:
Rightlick the night version of your light and select Light > SpotLight
Now rotate and move your light like you wish. You can move and rotate the light with the gizmo handles.
We recommend emissive maps to have the look of a real lighting lamp. This is optional and not absolutely needed.
Our page Emissive Textures can help you if you do not know something about emissive textures.
For the case you want to use an emissive texture duplicate your material with Ctrl + D
.
Rename you duplicated material in a reasonable name. For example YourMaterialName_mat_e
.
Now activate the emissive of your material and assign the emissive texture as already mentioned in the emissive tutorial.
At least we have to assign the emissive material to the object.
Therefore select the respective obect in the hierarchy on the left side and then drag the material from the project window to the inspector window in the right and drop it.
We will now add the On Create Lua Script
component:
Select the object at the top and click Add Component
.
Now type On Create Lua Script
and select it.
You now will have an empty Lua Script Component.
In this box you have to write following:
NightLight:onCreate(id, 16.25*60, 16.25*60, 8.25*60, 8.25*60);
The Day-Version will be shown from 8.25
to 16.25
.
The Night-Verison will be shown from 16.25
to 8.25
.
You can adjust the times just as you like.
It could look like this aswell:
NightLight:onCreate(id, 16.25*60, 17*60, 8*60, 9*60);
Now the nightlight will turn on soonest at 16.25
(16:15)
and at the latest at 17
(17:00)
.
The same takes effect for the day.
Have fun with your nightlight!