How can i center GUI BeginGroup C Sharp

Hello everyone,
I know there are A LOT of threads on how to center a GUI. but none of them worked
for me in C#. So i hoped some C # experts can help me out with this.

I use the usual code:

new Rect (Screen.width / 2 - 400, Screen.height / 2 - 300,400,800)

but it still gets a bit off the center. it usually lies a bit on the left. and i saw that quite few ppl had
the same issue.

Any C# ideas how i can work my way around?

Ofcoarse i could tweak the values, but im just wondering if i can do it more practical like in Java.

it shouldnt be off center if your values are right

float rectWidth = 400.0f;
float rectHeight = 800.0f;
new Rect (screen.width/2-(rectWidth/2), Screen.height/2-(rectHeight/2), rectWidth, rectHeight);

Thanks it works :slight_smile:

you didn’t divide your x and y values by 2

you say the width of your box was 400 so you should have the following

new Rect((Screen.width /2) - 200, (Screen.height / 2) - 400, 400, 800);

This one is tested and it works (C#), take a look at this post.