Hey,
I have an issue in my Resolution Settings.
Here is the Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.IO;
using TMPro;
using UnityEngine.UI;
public class Settings_Manager : MonoBehaviour{
#region Attributes
[SerializeField]
private Text resolutionText;
private Resolution[] resolutions;
private int currentResolutionIndex = 0;
private const string RESOLUTION_PREF_KEY = "Resolution";
#endregion
void Start(){
Resolution[] resolutions = Screen.resolutions;
currentResolutionIndex = PlayerPrefs.GetInt(RESOLUTION_PREF_KEY, 0);
resolutionText.text = Screen.currentResolution.width + "x" + Screen.currentResolution.height + "@" + Screen.currentResolution.refreshRate;
}
#region Resolution
private void SetResolutionText(Resolution resolution){
resolutionText.text = resolution.width + "x" + resolution.height + "@" + resolution.refreshRate;
}
public void SetNextResolution(){
currentResolutionIndex = GetNextWrappedIndex(resolutions, currentResolutionIndex);
SetResolutionText(resolutions[currentResolutionIndex]);
}
public void SetPreviousResolution()
{
currentResolutionIndex = GetPreviousWrappedIndex(resolutions, currentResolutionIndex);
SetResolutionText(resolutions[currentResolutionIndex]);
}
private int GetNextWrappedIndex<T>(IList<T> collection, int currentIndex){
if (collection.Count < 1) return 0;
return (currentIndex + 1) % collection.Count;
}
private int GetPreviousWrappedIndex<T>(IList<T> collection, int currentIndex){
if (collection.Count < 1) return 0;
if ((currentIndex - 1) < 0) return collection.Count - 1;
return (currentIndex - 1) % collection.Count;
}
private void SetAndApplyResolution(int newResolutionIndex){
currentResolutionIndex = newResolutionIndex;
ApplyCurrentResolution();
}
private void ApplyCurrentResolution(){
ApplyResolution(resolutions[currentResolutionIndex]);
}
private void ApplyResolution(Resolution resolution){
SetResolutionText(resolution);
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen, Screen.currentResolution.refreshRate);
PlayerPrefs.SetInt(RESOLUTION_PREF_KEY, currentResolutionIndex);
}
#endregion
public void ApplyChanges(){
SetAndApplyResolution(currentResolutionIndex);
}
}
An the 3 Errors
NullReferenceException: Object reference not set to an instance of an object
Settings_Manager.GetNextWrappedIndex[T] (System.Collections.Generic.IList`1[T] collection, System.Int32 currentIndex)
NullReferenceException: Object reference not set to an instance of an object
Settings_Manager.GetNextWrappedIndex[T] (System.Collections.Generic.IList`1[T] collection, System.Int32 currentIndex)
NullReferenceException: Object reference not set to an instance of an object
Settings_Manager.ApplyCurrentResolution ()