I want to change the skybox in my game through script depending on what skybox the player has chosen. Here's the code for that
if(SaveGame.Load<string>("Map").Contains("Night"))
{
dayLight.SetActive(false);
nightLight.SetActive(true);
RenderSettings.skybox =skyboxes[1];
}
else if(SaveGame.Load<string>("Map").Contains("Day"))
{
dayLight.SetActive(true);
nightLight.SetActive(false);
RenderSettings.skybox =skyboxes[0];
}
I can confirm that the error is not in the
SaveGame.Load<string>("Map)
because it actually does change the skybox. It changes it from night to day. However all the gameobjects in my scene become super dim and black. The only way I fix this is by dragging the skybox material from the Project tab to the scene view, everything becomes shiny again, but when I do it from script it's super dark. There are also no errors at all in the Console. How do I fix this?
CodePudding user response:
If Dynamic Global Illumination (Dynamic GI) is used the environment cube map needs to be updated after changing the skybox. it can be done like this:
DynamicGI.UpdateEnvironment();