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;
}
网友评论