private void CallLightning() { // 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 = 5; float duration = 0.3939312f; float delay = 0.0f; int seed = -210785313; System.Random r = new System.Random(seed); Vector3 start = new Vector3(0f, 241.0437f, 500f); Vector3 end = new Vector3(0f, -239.0398f, 500f); int generations = 5; float chaosFactor = 0.3054504f; float trunkWidth = 10.39684f; float glowIntensity = 0.201021f; 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; System.Collections.Generic.List <DigitalRuby.ThunderAndLightning.LightningBoltParameters> paramList = new System.Collections.Generic.List <DigitalRuby.ThunderAndLightning.LightningBoltParameters>(); 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 }; paramList.Add(parameters); delay += (singleDuration * (((float)r.NextDouble() * 0.8f) + 0.4f)); } script.CreateLightningBolts(paramList); }
private void CallLightning() { if (SpaceBarLabel != null) { SpaceBarLabel.CrossFadeColor(new Color(0.0f, 0.0f, 0.0f, 0.0f), 1.0f, true, true); SpaceBarLabel = null; } 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; System.Collections.Generic.List <LightningBoltParameters> paramList = new System.Collections.Generic.List <LightningBoltParameters>(); //UnityEngine.Profiling.Profiler.BeginSample("CreateLightningBolt"); System.Diagnostics.Stopwatch timer = System.Diagnostics.Stopwatch.StartNew(); 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, ChaosFactorForks = chaosFactor, TrunkWidth = trunkWidth, Intensity = IntensitySlider.value, GlowIntensity = GlowIntensitySlider.value, GlowWidthMultiplier = GlowWidthSlider.value, Forkedness = forkedness, RandomOverride = r, FadePercent = fadePercent, GrowthMultiplier = growthMultiplier }; paramList.Add(parameters); delay += (singleDuration * (((float)r.NextDouble() * 0.8f) + 0.4f)); } LightningBoltScript.CreateLightningBolts(paramList); timer.Stop(); //UnityEngine.Profiling.Profiler.EndSample(); UpdateStatusLabel(timer.Elapsed); }