Variable Resolution

Hello!

How can i make my game change his resolution according to the computer it is played on, so it will be stretched on the screen. I am building for Web or Flash.

It’s not too clear what you are asking for here. The Unity game engine automatically handles most screen resolution changes by itself. The only thing you need think about is the unity GUI. You need to create your GUI elements in terms of Screen.width and Screen.height. So instead of screen coordinates (0, 980) to get a element of x 0 and y 3/4 of the way up a screen, you would use screen coordinates (0, Screen.height*.75).

Well, this can be achieved with Screen.currentResolution, although if you’re looking for a variable storing this, here’s an example of something I found that works :slight_smile: :

using UnityEngine;

public class Example : MonoBehaviour;
{
Resolution resolution = Screen.currentResolution;

void Start ()
{
Debug.Log(resolution); //Prints: 1920x1080 @ 60hz (In my case, could be 1600 x 720 @ 30hz for ex.)
}

}

Although changing resolution? Alright. Let’s use the same method as before.

    using UnityEngine;
    
    public class Example : MonoBehaviour;
    {
    Resolution resolution = Screen.currentResolution; //This time, we are storing multiple resolutions
    Resolution res1;
    Resolution res2;

    public bool useRes1; //These are used to pick from the 2 resolutions
    public bool useRes2;
    
    void Start ()
    {
    res1.height = 600;
    res1.width = 800;

    res2.height = 768;
    res2.width = 1024;

    if (useRes1)
    {
        Screen.SetResolution(res1.width, res1.height, false); //False can be changed to true if we are running fullscreen, but since you are running flash it's not required
    }

    if (useRes2)
    {
        Screen.SetResolution(res2.width, res2.height, false);
    }
    }
    
    }