WeatherTool.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public enum WeatherType
  5. {
  6. sun,
  7. rain,
  8. snow
  9. }
  10. public class WeatherTool : MonoBehaviour
  11. {
  12. public WeatherType _CurrentWeatherType;
  13. public GameObject _flare;
  14. public ParticleSystem rain;
  15. public ParticleSystem snow;
  16. public static WeatherTool instance;
  17. private void Awake()
  18. {
  19. instance = this;
  20. }
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. if (Input.GetKeyDown(KeyCode.Alpha1))
  25. {
  26. _CurrentWeatherType = WeatherType.sun;
  27. UpdateWeather();
  28. }
  29. if (Input.GetKeyDown(KeyCode.Alpha2))
  30. {
  31. _CurrentWeatherType = WeatherType.rain;
  32. UpdateWeather();
  33. }
  34. if (Input.GetKeyDown(KeyCode.Alpha3))
  35. {
  36. _CurrentWeatherType = WeatherType.snow;
  37. UpdateWeather();
  38. }
  39. }
  40. public void UpdateWeather()
  41. {
  42. var rainEmission = rain.emission;
  43. var snowEmission = snow.emission;
  44. switch (_CurrentWeatherType)
  45. {
  46. case WeatherType.sun:
  47. _flare.SetActive(true);
  48. rainEmission.rateOverTime = 0;
  49. snowEmission.rateOverTime = 0;
  50. break;
  51. case WeatherType.rain:
  52. _flare.SetActive(false);
  53. rainEmission.rateOverTime = 1000;
  54. snowEmission.rateOverTime = 0;
  55. break;
  56. case WeatherType.snow:
  57. _flare.SetActive(false);
  58. rainEmission.rateOverTime = 0;
  59. snowEmission.rateOverTime = 1000;
  60. break;
  61. }
  62. }
  63. }