Example #1
0
    IEnumerator Flash()
    {
        // Brighten the scene significantly
        float originalIntensity = lighting.lightIntensity;

        lighting.SetIntensity(2);

        yield return(new WaitForSeconds(0.5f));

        // Change the ligtning spawn rate so it is more random
        // Need a check because the particle system does not immediately
        // stop when intensity is set to 0
        if (effectIntensity > 0)
        {
            SetIntensity(Random.Range(0.1f, 0.7f));
        }

        // Restore lighting
        lighting.SetIntensity(originalIntensity);
    }
Example #2
0
    public IEnumerator TransitionLight(Weather from, Weather to, WeatherLighting weatherLighting)
    {
        float duration       = transitionDuration;
        float elapsedTime    = 0.0f;
        float lightIntensity = from.lightIntensity;

        while (elapsedTime <= duration)
        {
            // Transition scene lighting
            lightIntensity = Mathf.Lerp(from.lightIntensity, to.lightIntensity, elapsedTime / duration);
            weatherLighting.SetIntensity(lightIntensity);

            elapsedTime += Time.deltaTime;
            yield return(null);
        }
    }
Example #3
0
    IEnumerator StartWeatherSystem()
    {
        nextWeather = null;

        // Used for overriding current weather
        currentWeatherChecker = currentWeather;
        weatherTimer          = currentWeather.weatherDuration;

        // Turn on current weather
        yield return(currentWeather.TransitionEffects(true));

        lighting.SetIntensity(currentWeather.lightIntensity);
        currentWeather.SetSoundVolume(maxVolume);

        // Using a timer instead of WaitFor so that the timer can be modified in the inspector
        while (weatherTimer > 0)
        {
            weatherTimer -= Time.deltaTime;
            yield return(null);
        }

        float randomRoll = Random.Range(0.0f, 1.0f);
        float chanceSum  = 0;

        // Setting next transition to be the last weather in the list be default, in case the user does not use the correct weights
        nextWeather = currentWeather.transitionWeathers[currentWeather.transitionWeathers.Count - 1];

        for (int i = 0; i < Mathf.Min(currentWeather.transitionWeathers.Count, currentWeather.probability.Count); i++)
        {
            chanceSum += currentWeather.probability[i];
            if (randomRoll <= chanceSum)
            {
                nextWeather = currentWeather.transitionWeathers[i];
                break;
            }
        }

        StartCoroutine(TransitionWeather(nextWeather));
    }