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); }