private void CallLightning() { if (SpaceBarLabel != null) { SpaceBarLabel.CrossFadeColor(new Color(0.0f, 0.0f, 0.0f, 0.0f), 1.0f, true, true); SpaceBarLabel = null; } UnityEngine.Profiling.Profiler.BeginSample("CreateLightningBolt"); System.Diagnostics.Stopwatch timer = System.Diagnostics.Stopwatch.StartNew(); lastStart = StartImage.transform.position + (Camera.main.transform.forward * DistanceSlider.value); lastEnd = EndImage.transform.position + (Camera.main.transform.forward * DistanceSlider.value); lastStart = Camera.main.ScreenToWorldPoint(lastStart); lastEnd = Camera.main.ScreenToWorldPoint(lastEnd); int count = (int)BoltCountSlider.value; float duration = DurationSlider.value; float delay = 0.0f; float chaosFactor = ChaosSlider.value; float trunkWidth = TrunkWidthSlider.value; float forkedness = ForkednessSlider.value; if (!int.TryParse(SeedInputField.text, out lastSeed)) { lastSeed = UnityEngine.Random.Range(int.MinValue, int.MaxValue); } System.Random r = new System.Random(lastSeed); float singleDuration = Mathf.Max(1.0f / 30.0f, (duration / (float)count)); float fadePercent = FadePercentSlider.value; float growthMultiplier = GrowthMultiplierSlider.value; while (count-- > 0) { LightningBoltParameters parameters = new LightningBoltParameters { Start = lastStart, End = lastEnd, Generations = (int)GenerationsSlider.value, LifeTime = (count == 1 ? singleDuration : (singleDuration * (((float)r.NextDouble() * 0.4f) + 0.8f))), Delay = delay, ChaosFactor = chaosFactor, TrunkWidth = trunkWidth, GlowIntensity = GlowIntensitySlider.value, GlowWidthMultiplier = GlowWidthSlider.value, Forkedness = forkedness, Random = r, FadePercent = fadePercent, GrowthMultiplier = growthMultiplier }; LightningBoltScript.CreateLightningBolt(parameters); delay += (singleDuration * (((float)r.NextDouble() * 0.8f) + 0.4f)); } timer.Stop(); UnityEngine.Profiling.Profiler.EndSample(); UpdateStatusLabel(timer.Elapsed); }
public void GenerateSpark() { // Important, make sure this script is assigned properly, or you will get null ref exceptions. DigitalRuby.ThunderAndLightning.LightningBoltScript script = gameObject.GetComponent <DigitalRuby.ThunderAndLightning.LightningBoltScript>(); int count = 1; float duration = 0.25f; float delay = 0.0f; System.Random r = new System.Random(); Vector3 start = this.sparkingStartPoint.transform.position; Vector3 end = this.sparkingEndPoint.transform.position; int generations = 6; float chaosFactor = 0.2f; float trunkWidth = 0.05f; float glowIntensity = 0.1793653f; float glowWidthMultiplier = 4f; float forkedness = 0.5f; float singleDuration = Mathf.Max(1.0f / 30.0f, (duration / (float)count)); float fadePercent = 0.15f; float growthMultiplier = 0f; while (count-- > 0) { DigitalRuby.ThunderAndLightning.LightningBoltParameters parameters = new DigitalRuby.ThunderAndLightning.LightningBoltParameters { Start = start, End = end, Generations = generations, LifeTime = (count == 1 ? singleDuration : (singleDuration * (((float)r.NextDouble() * 0.4f) + 0.8f))), Delay = delay, ChaosFactor = chaosFactor, TrunkWidth = trunkWidth, GlowIntensity = glowIntensity, GlowWidthMultiplier = glowWidthMultiplier, Forkedness = forkedness, Random = r, FadePercent = fadePercent, // set to 0 to disable fade in / out GrowthMultiplier = growthMultiplier }; script.CreateLightningBolt(parameters); delay += (singleDuration * (((float)r.NextDouble() * 0.8f) + 0.4f)); } }