If you're testing in the editor, then Screen.resolutions could return an empty array since it's not really running in a screen. If you make a build and then test it, then it should give you the correct resolutions and the highest one is your best bet for a native resolution. Now, the better way of doing this, is by a static variable (assuming you're running C#).
Just make a new script named StaticVariableHolder
(or something like that so you can remember it) and it should go something like this:
public class StaticVariableHolder : MonoBehaviour {
public static Resolution nativeResolution;
// Use this for initialization
void Start ()
{
DontDestroyOnLoad(gameObject);
nativeResolution = Screen.currentResolution;
//print(nativeResolution); //debug line to see if it actually sets the resolution
}
}
Now, add the script to some object like StaticVariables
(as I have done). This object will now persist through ALL scenes because it's not destroyed on level loads (so be sure to put this in one level only, it shouldn't matter if that level is loaded several times but I'm not sure). Anyway, to get this variable later on you need to some line like this:
Resolution nativeRes = StaticVariableHolder.nativeResolution;
Remember, you have to make sure the object is never lost (where the DontDestroyOnLoad
part comes in) and you have to make sure the variable is public and static, otherwise it won't be accessible unless you search for the object (we don't want that because using Find calls in Update calls will be a huge performance hog).
