private void WeatherChange() { if (type == 0) { if (Time.time - initTime <= 25) { backgroundColorsCurrent[0] = background.GetComponent <Renderer>().material.GetColor("_TopColor"); backgroundColorsCurrent[1] = background.GetComponent <Renderer>().material.GetColor("_BottomColor"); for (int i = 0; i < 3; i++) { mountainColorsPresent[i] = mountains[i].GetComponent <SpriteRenderer>().color; } foregroundObjectColorsPresent = foregroundObjects[0].GetComponent <SpriteRenderer>().color; if (DayNightCycle.timeOfDay < 12000 && DayNightCycle.timeOfDay >= 75000) //Night Time { //fog.GetComponent<ParticleSystem>().startColor = fogColor; background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[0], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[1], Time.deltaTime)); for (int i = 0; i < 3; i++) { mountains[i].GetComponent <SpriteRenderer>().color = Color.Lerp(mountainColorsPresent[i], mountainColors[0], Time.deltaTime); } for (int i = 0; i < foregroundObjects.Length; i++) { foregroundObjects[i].GetComponent <SpriteRenderer>().color = Color.Lerp(foregroundObjectColorsPresent, foregroundObjectColors[0], Time.deltaTime); } } else if (DayNightCycle.timeOfDay >= 12000 && DayNightCycle.timeOfDay < 29500) //Sun Rise { //fog.GetComponent<ParticleSystem>().startColor = Color.Lerp(fog.GetComponent<ParticleSystem>().startColor, Color.white, Time.deltaTime); background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[2], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[3], Time.deltaTime)); for (int i = 0; i < 3; i++) { mountains[i].GetComponent <SpriteRenderer>().color = Color.Lerp(mountainColorsPresent[i], mountainColors[1], Time.deltaTime); } for (int i = 0; i < foregroundObjects.Length; i++) { foregroundObjects[i].GetComponent <SpriteRenderer>().color = Color.Lerp(foregroundObjectColorsPresent, foregroundObjectColors[1], Time.deltaTime); } } else if (DayNightCycle.timeOfDay >= 29500 && DayNightCycle.timeOfDay < 56000)//Day Time { //fog.GetComponent<ParticleSystem>().startColor = Color.white; background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[4], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[5], Time.deltaTime)); for (int i = 0; i < 3; i++) { mountains[i].GetComponent <SpriteRenderer>().color = Color.Lerp(mountainColorsPresent[i], mountainColors[2], Time.deltaTime); } for (int i = 0; i < foregroundObjects.Length; i++) { foregroundObjects[i].GetComponent <SpriteRenderer>().color = Color.Lerp(foregroundObjectColorsPresent, foregroundObjectColors[2], Time.deltaTime); } } else if (DayNightCycle.timeOfDay >= 56000 && DayNightCycle.timeOfDay < 75000)//Sun set { //fog.GetComponent<ParticleSystem>().startColor = Color.Lerp(fog.GetComponent<ParticleSystem>().startColor, fogColor, Time.deltaTime); background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[6], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[7], Time.deltaTime)); for (int i = 0; i < 3; i++) { mountains[i].GetComponent <SpriteRenderer>().color = Color.Lerp(mountainColorsPresent[i], mountainColors[3], Time.deltaTime); } for (int i = 0; i < foregroundObjects.Length; i++) { foregroundObjects[i].GetComponent <SpriteRenderer>().color = Color.Lerp(foregroundObjectColorsPresent, foregroundObjectColors[3], Time.deltaTime); } } if (x > numLightning) { lightning.SetActive(false); } if (x <= numLightning) { if (Time.time - initTime > randomTime[0] || Time.time - initTime > randomTime[1]) { lightning.GetComponent <Transform>().position = new Vector3(Random.Range(-6.5f, 6.5f), lightning.GetComponent <Transform>().position.y, lightning.GetComponent <Transform>().position.z); lightning.SetActive(true); background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.white); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.white); for (int i = 0; i < 3; i++) { mountains[i].GetComponent <SpriteRenderer>().color = Color.white; } for (int i = 0; i < foregroundObjects.Length; i++) { foregroundObjects[i].GetComponent <SpriteRenderer>().color = Color.white; } x++; } } initChangeBackTime = DayNightCycle.timeOfDay; backgroundColorsFinal[0] = dayNightCycle.GetBackgroundColorTop(initChangeBackTime); backgroundColorsFinal[1] = dayNightCycle.GetBackgroundColorBottom(initChangeBackTime); for (int i = 0; i < 3; i++) { mountainColorsFinal[i] = dayNightCycle.GetMountainColor(initChangeBackTime, i); } foregroundObjectColorsFinal = dayNightCycle.GetForegroundObjectColor(initChangeBackTime); } else if (Time.time - initTime > 25 && Time.time - initTime <= 30) { frac = (DayNightCycle.timeOfDay - initChangeBackTime) / 2500; background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColorsFinal[0], frac)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColorsFinal[1], frac)); for (int i = 0; i < 3; i++) { mountains[i].GetComponent <SpriteRenderer>().color = Color.Lerp(mountainColorsPresent[i], mountainColorsFinal[i], frac); } for (int i = 0; i < foregroundObjects.Length; i++) { foregroundObjects[i].GetComponent <SpriteRenderer>().color = Color.Lerp(foregroundObjectColorsPresent, foregroundObjectColorsFinal, frac); } } else { weatherChanging = false; fog.SetActive(false); rain.SetActive(false); } } else { if (Time.time - initTime <= 25) { backgroundColorsCurrent[0] = background.GetComponent <Renderer>().material.GetColor("_TopColor"); backgroundColorsCurrent[1] = background.GetComponent <Renderer>().material.GetColor("_BottomColor"); if (DayNightCycle.timeOfDay < 12000 && DayNightCycle.timeOfDay >= 75000) //Night Time { background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[8], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[9], Time.deltaTime)); } else if (DayNightCycle.timeOfDay >= 12000 && DayNightCycle.timeOfDay < 29500) //Sun Rise { background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[10], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[11], Time.deltaTime)); } else if (DayNightCycle.timeOfDay >= 29500 && DayNightCycle.timeOfDay < 56000)//Day Time { background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[12], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[13], Time.deltaTime)); } else if (DayNightCycle.timeOfDay >= 56000 && DayNightCycle.timeOfDay < 75000)//Sun set { background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColors[14], Time.deltaTime)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColors[15], Time.deltaTime)); } initChangeBackTime = DayNightCycle.timeOfDay; backgroundColorsFinal[0] = dayNightCycle.GetBackgroundColorTop(initChangeBackTime); backgroundColorsFinal[1] = dayNightCycle.GetBackgroundColorBottom(initChangeBackTime); } else if (Time.time - initTime > 25 && Time.time - initTime <= 30) { frac = (DayNightCycle.timeOfDay - initChangeBackTime) / 2500; background.GetComponent <Renderer>().material.SetColor("_TopColor", Color.Lerp(backgroundColorsCurrent[0], backgroundColorsFinal[0], frac)); background.GetComponent <Renderer>().material.SetColor("_BottomColor", Color.Lerp(backgroundColorsCurrent[1], backgroundColorsFinal[1], frac)); } else { weatherChanging = false; snow.SetActive(false); } } }