Hey guys I’m currently making a mini map to go on a screen. I need it to go in the top right of the screen. When placing things on the screen such as:
GUI.Label (Rect (0,Screen.height - 390,150,150), imageFile);
obviously the “0” in the first parameter is easy to do because it’s in the top left of the screen.
However, how would I code it to always be at the top RIGHT of any screen on any resolution? I’m sure it’s easy…just…unknown to me, lol.
You should subtract the rectangle width from the screen width. Supposing W and H are the image width and height:
GUI.Label (Rect(Screen.width - W, 0, W, H), imageFile);
EDITED: Well, I finnally got what’s the problem: you’ve altered the GUI scale using GUI matrix, but nobody told it to Screen.width. In other words, Screen.width is still expressed in scale 1, while all GUI itens are using the scale you’ve defined. The solution is to convert the screen width to this scale:
// calculate scale
var scale: float = Screen.height / nativeVerticalResolution;
var newScreenW: float = Screen.width / scale; // adjust screen width...
var newScreenH: float = nativeVerticalResolution; // and height
GUI.matrix = Matrix4x4.TRS(Vector3(0,0,0),Quaternion.identity,Vector3(scale,scale,1));
// the rect will be calculated using the new screen width:
GUI.Label (Rect(newScreenW - W, 0, W, H), imageFile);
// the same thing, but at the bottom-left corner:
GUI.Label (Rect(0, newScreenH - H, W, H), imageFile);