-
Notifications
You must be signed in to change notification settings - Fork 1
/
WeatherColor.cs
64 lines (51 loc) · 1.61 KB
/
WeatherColor.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeatherColor : MonoBehaviour
{
[Header("REFERENCES")]
[SerializeField] private Weather weather;
[SerializeField] private Material material;
[Header("COLORS")]
[SerializeField] private Color[] colors = new Color[Weather.States];
private Dictionary<Momentum, Color> weatherColors;
private Color currentColor;
private bool isUpdating;
private void Start()
{
weatherColors = new()
{
[Momentum.Sunny] = colors[0],
[Momentum.Cloudy] = colors[1],
[Momentum.Rainy] = colors[2],
[Momentum.Stormy] = colors[3]
};
}
private void FixedUpdate()
{
if (currentColor != weatherColors[weather.Momentum])
{
currentColor = weatherColors[weather.Momentum];
if (isUpdating)
{
StopCoroutine(ChangeColor());
}
StartCoroutine(ChangeColor());
}
}
private IEnumerator ChangeColor()
{
isUpdating = true;
Color iniColor = new(material.color.r, material.color.g, material.color.b, material.color.a);
Color endColor = weatherColors[weather.Momentum];
float secondsElapsed = 0;
while (secondsElapsed < weather.TransitionSeconds)
{
material.color = Color.Lerp(iniColor, endColor, secondsElapsed / weather.TransitionSeconds);
secondsElapsed += Time.deltaTime;
yield return null;
}
material.color = endColor;
isUpdating = false;
}
}