简体   繁体   中英

Lerp RenderSettings Skybox

How can I change the skybox slowly and smoothly. On my code it will check if the amplitude is less than equal to 0.7. It's working now but when I test it will change suddenly, I want to change it slowly. Any ideas? Appreciate your answers guys. Big thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DayNight : MonoBehaviour {

    public Light light;

    public Material nightSkyBox;

    public Material daySkyBox;

    public float duration;

    void Update() {

        float phi = Time.time / duration * 2 * Mathf.PI;

        float amplitude = Mathf.Cos (phi) * 1.0f + 1.0f;

        light.intensity = amplitude;

        if (amplitude <= 0.7f) {
            RenderSettings.skybox = nightSkyBox;
            light.color = new Color32 (68, 170, 255, 255);
        } else {
            RenderSettings.skybox = daySkyBox;
            light.color = new Color32 (255, 181, 99, 255);
        }
    }
}

For this use case I suggest you use the unity built in animation system. Just create an animator for your camera and change the skybox via keyframes for night and day

I cant test right now but you should be able to do something like this. Adjust the float parameter for different timing.

RenderSettings.skybox.Lerp(daySkyBox, nightSkyBox, 1f);

You will probably have to lerp back once its day time again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM