0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;

public class SettingsMenu : MonoBehaviour
{

    public AudioMixer audioMixer;

    public Dropdown resolutionDropdown;

    Resolution[] resolutions;

    void Start()
    {
        resolutions = Screen.resolutions;

        resolutionDropdown.ClearOptions();

        List<string> options = new List<string>();

        int currentResolution;
        
        for (int i = 0; i < resolutions.Length; i++)
        {
            string option = resolutions [i].width + " x " + resolutions[i].height;
            options.Add(option);

            if (resolutions[i].width == Screen.currentResolution.width &&
                resolutions[i].height == Screen.currentResolution.height)
            {
                currentResolutionIndex = i;
            }
        }
        resolutionDropdown.AddOptions(options);
        resolutionDropdown.value = currentResolutionIndex;
        resolutionDropdown.RefreshShownValue();
    }

    public void SetResolution (int resolutionIndex)
    {
        Resolution resolution = resolutions[resolutionIndex];
        Screen.SetResolution(resolution. width, resolution.height, Screen.fullScreen);
    }

    public void SetVolume (float volume)
    {
        audioMixer.SetFloat("Volume", volume);
    }

    public void SetQuality (int qualityIndex)
    {
        QualitySettings.SetQualityLevel(qualityIndex);
    }

    public void SetFullScreen (bool isFullScreen)
    {
        Screen.fullScreen = isFullScreen;
    }
}

pls help because the Unity Engine is making Errors that i dont understand maybe its the tutorial thats from 2017, i dont know but it would be great if you could help me. it has something to do with current Resolution Index if you need more context pls write me

1 Answers1

0

Compiler Error CS0103 is caused by using an undeclared variable or method. This issue happens where the currentResolutionIndex variable is never defined in the file.

void Start()
{
    /* Added the following line of code. To manage this condition when the condition is not always true, the variable must be initialized. */
    int currentResolutionIndex = -1;
    
    for (int i = 0; i < resolutions.Length; i++)
    {
        /* This condition may not always be true. */
        if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
        {
            currentResolutionIndex = i;
        }
    }
   
    /* If the condition never works correctly, you should control and manage this condition. */
    if(currentResolutionIndex != -1)
    {
        resolutionDropdown.value = currentResolutionIndex;
    }
    else
    {
        /* Exception Handling */
    }
}
Sercan
  • 4,739
  • 3
  • 17
  • 36