Rect Struct

A 2D Rectangle defined by x, y position and width, height.

The Rect structure is mainly used for 2D operations. The UnityGUI system uses it extensively and it is also to set the onscreen position of a Camera's view.

The rectangle can be specified in two different ways. The first way involves supplying the top-left corner coordinate along with the width and height. This is done using the x, y, width and height properties.

The second way to specify the rectangle is to supply the X coordinates of its left and right sides and the Y coordinates of its top and bottom sides. These are denoted by the xMin, xMax, yMin and yMax properties. Although the x and y properties may seem to be the same as xMin and xMax, their behaviour is actually slightly different. The x and y values are assumed to be used along with width and height. This means that if you change x or y without changing width or height then the rectangle will change position but stay the same size. On the other hand, if you change the values of xMin or yMin without changing xMax or yMax then the rectangle will change size and the top-left corner will also change.

See Also: GUI Scripting Guide, Camera.rect, Camera.pixelRect.

Variables
x

Left coordinate of the rectangle.

y

Top coordinate of the rectangle.

center

Center coordinate of the rectangle.

width

Width of the rectangle.

height

Height of the rectangle.

xMin

Left coordinate of the rectangle.

yMin

Top coordinate of the rectangle.

xMax

Right coordinate of the rectangle.

yMax

Bottom coordinate of the rectangle.

Constructors
Rect

Creates a new rectangle.

Functions
Set

Set components of an existing Rect.

ToString

Returns a nicely formatted string for this Rect.

Contains

Class Functions
MinMaxRect

operator !=

Returns true if the rectangles are different.

operator ==

Returns true if the rectangles are the same.