Files
3D-FPS/3D FPS/Assets/Scripts/SettingsMenu.cs
Michal Sedlák c40fda000e Added pause menu
Pause menu with settings
2024-12-11 20:55:11 +01:00

59 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class SettingsMenu : MonoBehaviour
{
public AudioMixer audioMixer;
public TMP_Dropdown resolutionDropdown;
Resolution[] resolutions;
int currentResolutionIndex;
void Start()
{
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
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.width && resolutions[i].height == Screen.height) currentResolutionIndex = i;
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
public void ContinueButton()
{
gameObject.SetActive(false);
}
public void setVolume(float vol)
{
audioMixer.SetFloat("Volume", vol);
}
public void setQuality(int qualityIndex)
{
QualitySettings.SetQualityLevel(qualityIndex);
}
public void setFullscreen(bool isFullscreen)
{
Screen.fullScreen = isFullscreen;
}
public void setResolution(int resolutionIndex)
{
Screen.SetResolution(resolutions[resolutionIndex].width, resolutions[resolutionIndex].height, FullScreenMode.FullScreenWindow);
}
}