示例#1
0
    IEnumerator FadeSun()
    {
        while (player != null) //Check for reaching max distance instead maybe?
        {
            sunScript.setLightIntensity = false;
            sunScript.setAmbientColor   = false;

            if (SetFogColor)
            {
                sunScript.setFogColor = false;
            }

            Vector3 startToEnd     = fadeEnd.position - fadeStart.position;
            Vector3 startToPlayer  = player.position - fadeStart.position;
            Vector3 positionOnLine = Vector3.Project(startToPlayer, startToEnd);

            if (Vector3.Dot(positionOnLine, startToEnd) < 0)
            {
                positionOnLine = Vector3.zero;
            }

            progress = positionOnLine.magnitude / fadeLineLength;
            progress = Mathf.Clamp01(progress);

            Color origAmb = sunScript.ambientColor.Evaluate(sunScript.timeOfDay / 24f);
            RenderSettings.ambientLight = Color.Lerp(origAmb, NewAmbientColor, progress);

            float origSunIntensity            = sunScript.GetCurrentSunIntensity();
            sunScript.GetSunLight().intensity = Mathf.Lerp(origSunIntensity, NewIntensity, progress);

            Color origFogColor = sunScript.fogColor.Evaluate(sunScript.timeOfDay / 24f);
            RenderSettings.fogColor = Color.Lerp(origFogColor, NewFogColor, progress);

            yield return(null);
        }
        sunScript.setLightIntensity = true;
        sunScript.setAmbientColor   = true;

        if (SetFogColor)
        {
            sunScript.setFogColor = true;
        }
    }