Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Vector2Int

Representation of 2D vectors and points using integers.
Read time 2 minutesLast updated 6 days ago

Definition

public struct Vector2Int : IEquatable<Vector2Int>, IFormattable

Remarks

This structure is used in some places to represent 2D positions and vectors that don't require the precision of floating-point.

Properties

Property

Description

this[]Access the x or y component using [0] or [1] respectively.
magnitudeReturns the length of this vector (Read Only).
sqrMagnitudeReturns the squared length of this vector (Read Only).
xX component of the vector.
yY component of the vector.

Static Properties

Property

Description

downShorthand for writing
Vector2Int(0, -1)
.
leftShorthand for writing
Vector2Int(-1, 0)
.
oneShorthand for writing
Vector2Int(1, 1)
.
rightShorthand for writing
Vector2Int(1, 0)
.
upShorthand for writing
Vector2Int(0, 1)
.
zeroShorthand for writing
Vector2Int(0, 0)
.

Methods

Method

Description

ClampClamps the
Vector2Int
to the bounds given by
min
and
max
.
EqualsEvaluates if a vector and obejct are equal to each other.
GetHashCodeGets the hash code for the Vector2Int.
ScaleMultiplies every component of this vector by the same component of
scale
.
SetSet x and y components of an existing Vector2Int.
ToStringFormats this vector as a string.

Static Methods

Method

Description

CeilToIntConverts a Vector2 to a Vector2Int by doing a Ceiling to each value.
DistanceCalculates the distance between two vectors.
FloorToIntConverts a Vector2 to a Vector2Int by doing a Floor to each value.
MaxCreates a vector that is made from the largest components of two vectors.
MinCreates a vector that is made from the smallest components of two vectors.
RoundToIntConverts a Vector2 to a Vector2Int by doing a Round to each value.
ScaleMultiplies two vectors component-wise.

Operators

Operator

Description

operator +Adds two vectors.
operator /Divides a vector by a number.
operator ==Returns true if the vectors are equal.
Vector3IntConverts a Vector2Int to a Vector3Int.
Vector2Converts a Vector2Int to a Vector2.
operator !=Returns true if the vectors are different.
operator *Multiplies a vector by a number.
operator -Subtracts one vector from another.