Is there a way to save a change to a skybox in game.

I made a button that changes the skybox when clicked. I’m trying to save the skybox change.

Sorry for asking such a simple question but I haven’t been able to find a solution on the internet.

Yes, you can save the skybox change by using Unity’s PlayerPrefs system to store the current skybox name or material. Here’s an example of how you can do it:

Create a new script called “SkyboxManager” and attach it to an empty game object in your scene.
In the SkyboxManager script, define a public string variable to store the current skybox name or material. For example:
public class SkyboxManager : MonoBehaviour
{
public string currentSkyboxName;
}
In the script that handles the skybox change, update the SkyboxManager’s currentSkyboxName variable to the name or material of the newly selected skybox. For example:

public class SkyboxChanger : MonoBehaviour
{
    public SkyboxManager skyboxManager;
    public Material newSkyboxMaterial;

    public void ChangeSkybox()
    {
        RenderSettings.skybox = newSkyboxMaterial;
        skyboxManager.currentSkyboxName = newSkyboxMaterial.name;
        PlayerPrefs.SetString("currentSkyboxName", newSkyboxMaterial.name);
    }
}

When the skybox change button is clicked, call the ChangeSkybox() method to update the skybox and save the current skybox name using PlayerPrefs. For example:

public class SkyboxButton : MonoBehaviour
{
    public SkyboxChanger skyboxChanger;

    public void OnButtonClick()
    {
        skyboxChanger.ChangeSkybox();
    }
}

Now, when the skybox is changed, the current skybox name will be saved using PlayerPrefs. You can load the saved skybox name in the SkyboxManager’s Start() method by calling PlayerPrefs.GetString(“currentSkyboxName”). This will allow you to set the skybox to the last selected skybox when the game is restarted.