LightningBoltShapeSphereScript.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Procedural Lightning for Unity
  3. // (c) 2015 Digital Ruby, LLC
  4. // Source code may be used for personal or commercial projects.
  5. // Source code may NOT be redistributed or sold.
  6. //
  7. using UnityEngine;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. namespace DigitalRuby.ThunderAndLightning
  11. {
  12. /// <summary>
  13. /// Lightning bolt sphere shape script, creates lightning inside a sphere
  14. /// </summary>
  15. public class LightningBoltShapeSphereScript : LightningBoltPrefabScriptBase
  16. {
  17. /// <summary>Radius inside the sphere where lightning can emit from</summary>
  18. [Header("Lightning Sphere Properties")]
  19. [Tooltip("Radius inside the sphere where lightning can emit from")]
  20. public float InnerRadius = 0.1f;
  21. /// <summary>Radius of the sphere</summary>
  22. [Tooltip("Radius of the sphere")]
  23. public float Radius = 4.0f;
  24. #if UNITY_EDITOR
  25. /// <summary>
  26. /// OnDrawGizmos
  27. /// </summary>
  28. protected override void OnDrawGizmos()
  29. {
  30. base.OnDrawGizmos();
  31. Gizmos.DrawWireSphere(transform.position, InnerRadius);
  32. Gizmos.DrawWireSphere(transform.position, Radius);
  33. }
  34. #endif
  35. /// <summary>
  36. /// Create a lightning bolt
  37. /// </summary>
  38. /// <param name="parameters">Parameters</param>
  39. public override void CreateLightningBolt(LightningBoltParameters parameters)
  40. {
  41. Vector3 start = UnityEngine.Random.insideUnitSphere * InnerRadius;
  42. Vector3 end = UnityEngine.Random.onUnitSphere * Radius;
  43. parameters.Start = start;
  44. parameters.End = end;
  45. base.CreateLightningBolt(parameters);
  46. }
  47. }
  48. }