美文网首页
天空色渐变

天空色渐变

作者: 沉麟 | 来源:发表于2019-10-22 19:21 被阅读0次
    IEnumerator IChangeColor(int id)
        {        
            yield return null;
            float timer = 0;
            //记录当前天空色
            Color[] nowColors = new Color[3] { RenderSettings.skybox.GetColor("_TopColor"), RenderSettings.skybox.GetColor("_MiddleColor"), RenderSettings.skybox.GetColor("_BottomColor") };
            //创建临时天空色
            Color[] tmpColors = new Color[3];
            while (timer < 1.0f)
            {
                timer += Time.deltaTime;
                for (int i = 0; i < nowColors.Length; i++)
                {
                    tmpColors[i] = Color.Lerp(nowColors[i], colors[id%5, i], timer);//一秒渐变到需要的颜色
                }            
                //将渐变的颜色赋给天空色
                RenderSettings.skybox.SetColor("_TopColor", tmpColors[0]);
                RenderSettings.skybox.SetColor("_MiddleColor", tmpColors[1]);
                RenderSettings.skybox.SetColor("_BottomColor", tmpColors[2]);
                yield return null;
    
            }
            yield return null;
        }
    

    相关文章

      网友评论

          本文标题:天空色渐变

          本文链接:https://www.haomeiwen.com/subject/tyffuctx.html