-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnvironmentMangerScript.cs
42 lines (37 loc) · 1.17 KB
/
EnvironmentMangerScript.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class EnvironmentMangerScript : MonoBehaviour {
// Start is called before the first frame update
public Material Day, Sunset, Night;
private Material currentMaterial;
void Start() {
int hour = DateTime.Now.Hour;
if (hour < 17 && hour > 8) {
RenderSettings.skybox = Day;
} else if (hour >= 17 && hour < 19) {
RenderSettings.skybox = Sunset;
} else {
RenderSettings.skybox = Night;
}
currentMaterial = RenderSettings.skybox;
}
void OnApplicationFocus(bool focus) {
if (focus) {
int hour = DateTime.Now.Hour;
Material newMaterial;
if (hour < 17 && hour > 8) {
newMaterial = Day;
} else if (hour >= 17 && hour < 19) {
newMaterial = Sunset;
} else {
newMaterial = Night;
}
if (newMaterial != currentMaterial) {
RenderSettings.skybox = newMaterial;
currentMaterial = newMaterial;
}
}
}
}