RainScript.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Rain Maker (c) 2015 Digital Ruby, LLC
  3. // http://www.digitalruby.com
  4. //
  5. using UnityEngine;
  6. using System.Collections;
  7. namespace DigitalRuby.RainMaker
  8. {
  9. public class RainScript : BaseRainScript
  10. {
  11. [Tooltip("The height above the camera that the rain will start falling from")]
  12. public float RainHeight = 25.0f;
  13. [Tooltip("How far the rain particle system is ahead of the player")]
  14. public float RainForwardOffset = -7.0f;
  15. [Tooltip("The top y value of the mist particles")]
  16. public float RainMistHeight = 3.0f;
  17. private void UpdateRain()
  18. {
  19. // keep rain and mist above the player
  20. if (RainFallParticleSystem != null)
  21. {
  22. if (FollowCamera)
  23. {
  24. var s = RainFallParticleSystem.shape;
  25. s.shapeType = ParticleSystemShapeType.ConeVolume;
  26. RainFallParticleSystem.transform.position = Camera.transform.position;
  27. RainFallParticleSystem.transform.Translate(0.0f, RainHeight, RainForwardOffset);
  28. RainFallParticleSystem.transform.rotation = Quaternion.Euler(0.0f, Camera.transform.rotation.eulerAngles.y, 0.0f);
  29. if (RainMistParticleSystem != null)
  30. {
  31. var s2 = RainMistParticleSystem.shape;
  32. s2.shapeType = ParticleSystemShapeType.Hemisphere;
  33. Vector3 pos = Camera.transform.position;
  34. pos.y += RainMistHeight;
  35. RainMistParticleSystem.transform.position = pos;
  36. }
  37. }
  38. else
  39. {
  40. var s = RainFallParticleSystem.shape;
  41. s.shapeType = ParticleSystemShapeType.Box;
  42. if (RainMistParticleSystem != null)
  43. {
  44. var s2 = RainMistParticleSystem.shape;
  45. s2.shapeType = ParticleSystemShapeType.Box;
  46. Vector3 pos = RainFallParticleSystem.transform.position;
  47. pos.y += RainMistHeight;
  48. pos.y -= RainHeight;
  49. RainMistParticleSystem.transform.position = pos;
  50. }
  51. }
  52. }
  53. }
  54. protected override void Start()
  55. {
  56. base.Start();
  57. }
  58. protected override void Update()
  59. {
  60. base.Update();
  61. UpdateRain();
  62. }
  63. }
  64. }