``````		Rect r = new Rect(Screen.width * (1 - widthPercent) / 2,
Screen.height * (1 - heightPercent) / 2,
Screen.width * widthPercent,
Screen.height * heightPercent);

// draw the logo which will be centered at the top right of the menu
if (logo != null)
{
Rect i = new Rect(r.x + r.width - logo.width / 2,
r.y - logo.height - 2,
logo.width,
logo.height);
GUI.DrawTexture(i, logo);
}
``````

It comes from this tutorial: http://noobtuts.com/programming/unity/tower-defense-game-step-2-menu

I followed the previous tutorials on that website but this code here I’m really not sure what it means. If someone could walk through it step by step it would be great.

Have you checked out the GUI basics:

And this:

I have yes. I’m guessing the rect parameters in the parenthesis are for the x, y, width and height of the rect. However, why was one used for (1 - heightPercent)? Then, why was: Screen.width * widthPercent and Screen.height * heightPercent); used? Is it used to set the actual button location to hat was used above those?

What it looks like they have done is to use GUILayout for the buttons.

The first bit defines the rectangle the layout will be contained in, just using some maths to work out the size based on the screen size

The next part is just the location of the logo relative to this rectangle.

so lets say the screen size is 800 x 600 then the first part defining rectangle r would be:

``````Rect r = new Rect(800 * (1 - 0.3) / 2, 600 * (1 - 0.3) / 2, 800 * 0.3 ,600 * 0.3);

Rect r = new Rect(280, 210, 240, 180);
``````

This just creates a rectangle that is 30% of the screen size and positions it so it is in the center of the screen

Now if the logo texture is 64 x 32 then

``````Rect i = new Rect(r.x + r.width - logo.width / 2,r.y - logo.height / 2,logo.width,logo.height);

Rect i = new Rect(280 + 240 - 64 / 2, 210 - 32 / 2,64,32);

Rect i = new Rect(488, 194, 64, 32);
``````

This is just creating the space for the logo relative to the menu rectangle

Nice, thanks man.