using System.Collections; using System.Collections.Generic; using UnityEngine; public enum WeatherType { sun, rain, snow } public class WeatherTool : MonoBehaviour { public WeatherType _CurrentWeatherType; public GameObject _flare; public ParticleSystem rain; public ParticleSystem snow; public static WeatherTool instance; private void Awake() { instance = this; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Alpha1)) { _CurrentWeatherType = WeatherType.sun; UpdateWeather(); } if (Input.GetKeyDown(KeyCode.Alpha2)) { _CurrentWeatherType = WeatherType.rain; UpdateWeather(); } if (Input.GetKeyDown(KeyCode.Alpha3)) { _CurrentWeatherType = WeatherType.snow; UpdateWeather(); } } public void UpdateWeather() { var rainEmission = rain.emission; var snowEmission = snow.emission; switch (_CurrentWeatherType) { case WeatherType.sun: _flare.SetActive(true); rainEmission.rateOverTime = 0; snowEmission.rateOverTime = 0; break; case WeatherType.rain: _flare.SetActive(false); rainEmission.rateOverTime = 1000; snowEmission.rateOverTime = 0; break; case WeatherType.snow: _flare.SetActive(false); rainEmission.rateOverTime = 0; snowEmission.rateOverTime = 1000; break; } } }