Version: 5.6 (switch to 2017.1b)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Rect Constructor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public Rect(x: float, y: float, width: float, height: float)
public Rect(float x, float y, float width, float height);

Parameters

x The X value the rect is measured from.
y The Y value the rect is measured from.
width The width of the rectangle.
height The height of the rectangle.

Description

Creates a new rectangle.

var rect = Rect (0, 0, 10, 10);
          Rect rect = new Rect(0, 0, 10, 10);

Note: Rect represents an abstract rectangle, and can be used in a variety of situations. As such, Rects don't have an explicit top, bottom, left or right. For example, Y values in Camera space are measured from the bottom of the screen, but Y values in Editor GUI space are measured from the top of the window, therefore whether the Y value of a Rect is its "top" or "bottom" will vary depending on where you use the Rect value. You can refer to the corners by using Rect.min and Rect.max.


public Rect(position: Vector2, size: Vector2)
public Rect(Vector2 position, Vector2 size);

Parameters

position The position of the minimum corner of the rect.
size The width and height of the rect.

Description

Creates a rectangle given a size and position.

This form of the constructor is convenient when you are already working with Vector2 values.