I have a 2d game and I wand to make it looks good for different screen resolutions.
That’s why I want to scale my game objects automatically.
How can I know in Unity, what resolution is now used on the computer?
Or I only can propose to choose it before the game?
You can use Screen.resolutions to get an array of resolutions available. From there it’s really up to you on how you want to implement it. Here’s some example code from the Unity Scripting Reference:
public class ExampleClass : MonoBehaviour {
void Start() {
Resolution[] resolutions = Screen.resolutions;
foreach (Resolution res in resolutions) {
print(res.width + "x" + res.height);
}
Screen.SetResolution(resolutions[0].width, resolutions[0].height, true);
}
}
This goes through and grabs all available resolutions, prints them to the console, and finally sets the current screen resolution to the first resolution in the array, which should be the lowest resolution, sorted by width.