Resolution Script not working

Hi everyone,

I’m currently stuck with the problem of android resolutions and I just wanted get all resolutions possible with the standard unity script:

    function Start()
    {
        var resolutions : Resolution[] = Screen.resolutions;
        // Print the resolutions
        for (var res in resolutions) {
            print(res.width + "x" + res.height);
        }
        // Switch to the lowest supported fullscreen resolution
        Screen.SetResolution (resolutions[0].width, resolutions[0].height, true);
    };

but when trying this, I’ll get some errors:

Assets/Resolution.js(5,49): BCE0022: Cannot convert 'UnityEngine.Resolution[]' to 'Resolution[]'.
Assets/Resolution.js(8,23): BCE0019: 'width' is not a member of 'Resolution'.

Does anyone know, why this is not working?

Try this:

   var resolutions : UnityEngine.Resolution[] = Screen.resolutions;

It looks like you’ve also named your class Resolution, so when you’re declaring your variable as an array of “Resolution” it’s thinking that you’re wanting the type you’ve defined, while Screen.resolutions is of type UnityEngine.Resolutions[ ].

That will also fix your second error… because it’s looking for a “width” property on the type you defined when your variable should be of type UnityEngine.Resolutions[ ]

Thanks for your advice, ill give it a try asap. Its funny because its the example script from the unity docs :smile: But not the first time have to fix it :smile: