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;
}
}请帮助,因为团结引擎的错误,我不明白,也许这是从2017年的教程,我不知道,但如果你能帮助我将是很好的。如果您需要更多的上下文,请写信给我,这与当前的分辨率索引有关
发布于 2021-12-21 00:51:15
编译器错误CS0103是由使用未声明的变量或方法引起的。如果currentResolutionIndex变量从未在文件中定义,则会发生此问题。
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 */
}
}https://stackoverflow.com/questions/70429519
复制相似问题