projetrunandgun/Assets/SettingsMenu.cs
Patience Zampasi 084dcf9903 Added MainMenu + PauseMenu + Settings
Need to fix PauseMenu when load fist level because it's always displayed
Need to find a way to access to DontDestroyOnLoad Objects to get back Settings Menu
2024-02-06 23:55:01 +01:00

62 lines
1.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
using System.Linq;
public class SettingsMenu : MonoBehaviour
{
Resolution[] resolutions;
public AudioMixer audioMixer;
public Dropdown resolutionDropdown;
public void Start()
{
resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct().ToArray();
resolutionDropdown.ClearOptions();
List<string> listOptions = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + " x " + resolutions[i].height;
listOptions.Add(option);
if (resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
{
currentResolutionIndex = i;
}
}
resolutionDropdown.AddOptions(listOptions);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
Screen.fullScreen = true;
}
public void SetVolume(float volume)
{
audioMixer.SetFloat("Volume", volume);
}
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);
}
}