How to Set my current screen resolution to my in game resolution when entering the game?

Hello!

I want to know how to set players screen resolution to the game resolution settings, when they are entering the game. For me, when I am entering the game now it doesn’t set my screen resolution to the game current resolution I have.

Please I need someone to help me deal with that.

Here is my code:

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.Audio;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using System.Collections;


public class SettingsManager : MonoBehaviour
{
    // Variables that we are using in our code!

    [SerializeField] private Slider menuMusicVolumeSlider;
    [SerializeField] private TextMeshProUGUI menuMusicVolumeSliderText;

    [SerializeField] private Slider soundsVolumeSlider;
    [SerializeField] private TextMeshProUGUI soundsVolumeSliderText;

    [SerializeField] private Slider gameVolumeSlider;
    [SerializeField] private TextMeshProUGUI gameVolumeSliderText;

    [SerializeField] private Slider masterVolumeSlider;
    [SerializeField] private TextMeshProUGUI masterVolumeSliderText;

    [SerializeField] private TMP_Dropdown qualityDropdown;
    [SerializeField] private TMP_Dropdown resolutionDropdown;

    [SerializeField] private Toggle fullScreenToggle;

    public AudioMixer myAudioMixer;

    private Resolution[] resolutions;

    private List<Resolution> filteredResolutions;

    private float currentRefreshRate;

    private int currentResolutionIndex = 0;

    const string menuMusicVol = "MenuMusicVolume";
    const string soundEffectsVol = "SoundsVolume";
    const string masterVol = "MasterVolume";
    const string gameMusicVol = "GameMusicVolume";

    [System.Obsolete]
    private void Awake()
    {
        Resolution currentResolution = Screen.currentResolution;
        Screen.SetResolution(currentResolution.width, currentResolution.height, true);

        resolutions = Screen.resolutions;

        filteredResolutions = new List<Resolution>();

        if (resolutionDropdown != null)
        {
            resolutionDropdown.ClearOptions();
        }

        currentRefreshRate = Screen.currentResolution.refreshRate;

        for (int i = 0; i < resolutions.Length; i++)
        {
            if (resolutions[i].refreshRate == currentRefreshRate)
            {
                filteredResolutions.Add(resolutions[i]);
            }
        }

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

        for (int i = 0; i < filteredResolutions.Count; i++)
        {
            string resolutionOption = filteredResolutions[i].width + "x" + filteredResolutions[i].height + " " + filteredResolutions[i].refreshRate + "Hz";
            options.Add(resolutionOption);

            if (filteredResolutions[i].width == Screen.width & filteredResolutions[i].height == Screen.height)
            {
                currentResolutionIndex = i;
            }
        }

        if (resolutionDropdown != null)
        {
            resolutionDropdown.AddOptions(options);
            resolutionDropdown.value = currentResolutionIndex;
            resolutionDropdown.RefreshShownValue();
        }
    }