Description
The Length
property of the Vector2
struct returns the magnitude of the vector. The magnitude, or length, of a vector is a measure of how long the vector is, calculated as the square root of the sum of the squares of its components. This property is useful for determining the size or distance represented by the vector in 2D space.
Usage
To access the Length
property, simply call it on an instance of Vector2
. This property is read-only and provides a float
value representing the vector's magnitude.
Example
Vector2 vector = new Vector2(3, 4);
float length = vector.Length;
// length will be 5, as the vector (3, 4) has a magnitude of 5 (3^2 + 4^2 = 9 + 16 = 25, sqrt(25) = 5)