-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_Night.cs
68 lines (63 loc) · 1.77 KB
/
Day_Night.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Day_Night : MonoBehaviour
{
public SpriteRenderer shadow;
private Color myColor;
private bool isDay;
void Start()
{
// At first, we check the time in which we are playing
myColor = shadow.color;
if ((System.DateTime.Now.Hour >= 0 && System.DateTime.Now.Hour < 8) || (System.DateTime.Now.Hour >= 20))
{
isDay = false;
}
else
{
isDay = true;
}
// We set the shadow transparency (To simulate a bit more the day or the night)
if (isDay)
{
myColor = shadow.color;
myColor.a = 0;
shadow.color = myColor;
}
else
{
myColor = shadow.color;
myColor.a = 1;
shadow.color = myColor;
}
}
// Update is called once per frame
void Update()
{
// If we have passed from day to night or night to day, put or take off the transparency gradually
if (!this.isDay.Equals(Proceduralcreation.day))
{
if (Proceduralcreation.day)
{
myColor = shadow.color;
myColor.a -= 0.01f;
shadow.color = myColor;
if (shadow.color.a <= 0)
{
this.isDay = true;
}
}
else
{
myColor = shadow.color;
myColor.a += 0.01f;
shadow.color = myColor;
if (shadow.color.a >= 1)
{
this.isDay = false;
}
}
}
}
}