Quantcast
Channel: Latest Questions by LeviS
Viewing all articles
Browse latest Browse all 10

Taking the user's screen resolution before running a GUI.matrix?

$
0
0

Okay, I'm fairly new to GUIs, so correct me if I'm wrong.

  1. I can just use Screen.width and Screen.height, but without a matrix images will be stretched.

  2. To keep things in a good ratio, you use a GUI.matrix.

  3. The GUI.matrix needs the native resolution of the user to function properly.

So how can I take their native resolution and then plug those numbers into my matrix? Here is my code, just using my own native resolution (the relevant parts):

var nativeVerticalResolution = 1050.0;
var nativeHorizontalResolution = 1680.0;

GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3 (Screen.width / nativeHorizontalResolution, Screen.height / nativeVerticalResolution, 1));

GUI.Label(Rect ((nativeHorizontalResolution / 2) - (image.width / 2), 0, image.width, image.height), image);

This puts my image at the (center / top) of the screen and works great on my resolution. But it won't work as well on another resolution, I know because I wasted a ton of time when I had the nativeVerticalResolution set wrong.

Seems like at the moment I've set it up great to scale on any ratio I use on my computer, but I want it to work on any computer I move it to. Any solutions, or maybe I'm going about this the wrong way?

Thanks in advance!


Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>