光照射日夜変化システム
1422 ワード
日夜の明るさの変化を実現します
using UnityEngine;
using System.Collections;
/// <summary>
/// @brief is for weather system
/// </summary>
public class WeatherSystem : MonoBehaviour
{
[SerializeField]
private Light light;
private float _current_intensity = 1.0f;
// Use this for initialization
void Start()
{
StartCoroutine(SyncLight());
}
// Update is called once per frame
void Update()
{
}
IEnumerator SyncLight()
{
yield return new WaitForSeconds(10.0f);
for (; _current_intensity >= 0; _current_intensity -= 0.01f)
{
yield return new WaitForSeconds(1);
light.GetComponent<Light>().intensity = _current_intensity;
}
yield return new WaitForSeconds(5.0f);
for (_current_intensity = 0.0f; _current_intensity <= 1; _current_intensity += 0.01f)
{
yield return new WaitForSeconds(1);
light.GetComponent<Light>().intensity = _current_intensity;
}
StartCoroutine(SyncLight());
}
public void OnUIDayNight(bool _is)
{
if (_is)
{
StopAllCoroutines();
StartCoroutine(SyncLight());
}
else
{
StopAllCoroutines();
}
light.GetComponent<Light>().intensity = 1.0f;
}
}