I am having a problem with the resolution. The resolution is not saved. When I close the game and reopen it at first it opens fine and suddenly it changes to a default resolution and I have to change it again. I do not understand what is wrong in the code that the resolution is not saved. I already tried a thousand ways and I can’t solve it. Here is the code that I am using to change the resolution and save it:
public class LogicResolution : MonoBehaviour
{
public TMP_Dropdown resolutionsDropDown;
public int optionIndex;
void Start()
{
optionIndex = PlayerPrefs.GetInt("resolutionNumber", 2);
resolutionsDropDown.value = optionIndex;
AdjustResolution();
}
public void AdjustResolution()
{
if (resolutionsDropDown.value == 0)
Screen.SetResolution(640, 360, Screen.fullScreen);
else if (resolutionsDropDown.value == 1)
Screen.SetResolution(1280, 720, Screen.fullScreen);
else if (resolutionsDropDown.value == 2)
Screen.SetResolution(1920, 1080, Screen.fullScreen);
else if (resolutionsDropDown.value == 3)
Screen.SetResolution(3840, 2160, Screen.fullScreen);
PlayerPrefs.SetInt("resolutionNumber", resolutionsDropDown.value);
optionIndex = resolutionsDropDown.value;
}
The default value is 1280x720 when I actually set it to start with 1920x1080.