Hi,
so I get this StackOverflowException error when trying to change graphics settings in main menu, the options also don’t seem to be applied as in game mode there are no shadows when there should be. I’ve been looking at other posts for hours and seem to know what the issue is but cannot find what in my scrip is causing this.
The code:
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class SettingsMenu : MonoBehaviour
{
public AudioMixer mixer;
public Dropdown resolutionDropdown;
public Dropdown qualityDropdown;
public Dropdown textureDropdown;
public Dropdown aaDropdown;
public Slider volumeSlider;
public Slider slider;
Resolution[] resolutions;
// Start is called before the first frame update
void Start()
{
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
resolutions = Screen.resolutions;
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions*.width + " x " +*
resolutions*.height;*
options.Add(option);
if (resolutions*.width == Screen.currentResolution.width*
&& resolutions*.height == Screen.currentResolution.height)*
currentResolutionIndex = i;
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.RefreshShownValue();
LoadSettings(currentResolutionIndex);
}
public void SetLevel(float sliderValue)
{
mixer.SetFloat(“MasterVol”, Mathf.Log10(sliderValue) * 20);
PlayerPrefs.SetFloat(“MasterVolume”, sliderValue);
}
public void SetFullscreen(bool isFullscreen)
{
Screen.fullScreen = isFullscreen;
}
public void SetResolution(int resolutionIndex)
{
Resolution resolution = resolutions[resolutionIndex];
Screen.SetResolution(resolution.width,
resolution.height, Screen.fullScreen);
}
public void SetTextureQuality(int textureIndex)
{
QualitySettings.masterTextureLimit = textureIndex;
qualityDropdown.value = 6;
}
public void SetAntiAliasing(int aaIndex)
{
QualitySettings.antiAliasing = aaIndex;
qualityDropdown.value = 6;
}
public void SetQuality(int qualityIndex)
{
if (qualityIndex != 5) // if the user is not using
//any of the presets
QualitySettings.SetQualityLevel(qualityIndex);
switch (qualityIndex)
{
case 1: // quality level - low
textureDropdown.value = 2;
aaDropdown.value = 0;
break;
case 2: // quality level - medium
textureDropdown.value = 1;
aaDropdown.value = 0;
break;
case 3: // quality level - high
textureDropdown.value = 0;
aaDropdown.value = 0;
break;
case 4: // quality level - ultra
textureDropdown.value = 0;
aaDropdown.value = 2;
break;
}
qualityDropdown.value = qualityIndex;
}
public void ExitGame()
{
Application.Quit();
}
public void SaveSettings()
{
PlayerPrefs.SetInt(“QualitySettingPreference”,
qualityDropdown.value);
PlayerPrefs.SetInt(“ResolutionPreference”,
resolutionDropdown.value);
PlayerPrefs.SetInt(“TextureQualityPreference”,
textureDropdown.value);
PlayerPrefs.SetInt(“AntiAliasingPreference”,
aaDropdown.value);
PlayerPrefs.SetInt(“FullscreenPreference”,
Convert.ToInt32(Screen.fullScreen));
PlayerPrefs.GetFloat(“MasterVolume”,
slider.value);
}
public void LoadSettings(int currentResolutionIndex)
{
if (PlayerPrefs.HasKey(“QualitySettingPreference”))
qualityDropdown.value =
PlayerPrefs.GetInt(“QualitySettingPreference”);
else
qualityDropdown.value = 3;
if (PlayerPrefs.HasKey(“ResolutionPreference”))
resolutionDropdown.value =
PlayerPrefs.GetInt(“ResolutionPreference”);
else
resolutionDropdown.value = currentResolutionIndex;
if (PlayerPrefs.HasKey(“TextureQualityPreference”))
textureDropdown.value =
PlayerPrefs.GetInt(“TextureQualityPreference”);
else
textureDropdown.value = 0;
if (PlayerPrefs.HasKey(“AntiAliasingPreference”))
aaDropdown.value =
PlayerPrefs.GetInt(“AntiAliasingPreference”);
else
aaDropdown.value = 1;
if (PlayerPrefs.HasKey(“FullscreenPreference”))
Screen.fullScreen =
Convert.ToBoolean(PlayerPrefs.GetInt(“FullscreenPreference”));
else
Screen.fullScreen = true;
if (PlayerPrefs.HasKey(“VolumePreference”))
volumeSlider.value =
PlayerPrefs.GetFloat(“VolumePreference”);
else
volumeSlider.value =
PlayerPrefs.GetFloat(“VolumePreference”);
}
// Load game scene
public void GameScene()
{
SceneManager.LoadScene(“Game”);
}
}