How to place GUI elements relative into the screen

Hey guys,

is it possible to place gui elements such as buttons, boxes or whatever relatively to another element and not absolutely to the screen?

if i use GUI.Toggle(Rect(25, 25,50,50), “text”), it of cours generates a toggle 25 pixels from 0 with a size of 50x50pixels, but what i would like to do is place it inside a box, centered in that box and what i sure don’t want to do, is change that accordingly everytime i change the size of the box.

same goes to any element that is aligned to anything but the left side of the screen, how do i place something X and Y pixels from the bottom right edge of the screen?

Is that understandable? :sweat_smile:

Screen.width and Screen.height are your friends.

A quick example: How to center a toggle on the screen:

GUI.Toggle(new Rect(Screen.width * 0.5) - 25, (Screen.height * 0.5) - 25, 50, 50);