Vector4
Representation of four-dimensional vectors.
Read time 2 minutesLast updated 4 days ago
Definition
- Type: Struct
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Implements: IEquatable<Vector4>, IFormattable
public struct Vector4 : IEquatable<Vector4>, IFormattable
Remarks
This structure is used in some places to represent four component vectors (e.g. mesh tangents, parameters for shaders). In the majority of other cases a Vector3 is used.
Fields
Value | Description |
|---|---|
| w | W component of the vector. |
| x | X component of the vector. |
| y | Y component of the vector. |
| z | Z component of the vector. |
Constructors
Constructor | Description |
|---|---|
| Vector4(System.Single,System.Single) | Creates a new vector with given x, y components and sets |
| Vector4(System.Single,System.Single,System.Single) | Creates a new vector with given x, y, z components and sets |
| Vector4(System.Single,System.Single,System.Single,System.Single) | Creates a new vector with given x, y, z, w components. |
Properties
Property | Description |
|---|---|
| this[] | Access the x, y, z, w components using [0], [1], [2], [3] respectively. |
| magnitude | Returns the length of this vector (Read Only). |
| normalized | Creates a normalized copy of a vector based on the current vector. |
| sqrMagnitude | Returns the squared length of this vector (Read Only). |
Static Properties
Property | Description |
|---|---|
| negativeInfinity | Shorthand for writing |
| one | Shorthand for writing |
| positiveInfinity | Shorthand for writing |
| zero | Shorthand for writing |
Methods
Method | Description |
|---|---|
| Equals | Compares two vectors to each other and evaluates if they are equal. |
| Normalize | Makes this vector have a Vector4.magnitude of 1. |
| Scale | Multiplies every component of this vector by the same component of |
| Set | Set x, y, z and w components of an existing Vector4. |
| ToString | Formats this vector as a string. |
Static Methods
Method | Description |
|---|---|
| Distance | Returns the distance between a and b. |
| Dot | Calculates the dot product of two vectors. |
| Lerp | Linearly interpolates between two vectors. |
| LerpUnclamped | Linearly interpolates between two vectors. |
| Max | Creates a vector that is made from the largest components of two vectors. |
| Min | Creates a vector that is made from the smallest components of two vectors. |
| MoveTowards | Moves a point |
| Normalize | Returns a normalized vector based on the given vector. The normalized vector has a Vector4.magnitude of 1 and is in the same direction as the given vector. Returns a zero vector if the given vector is too small to be normalized. |
| Project | Projects a vector onto another vector. |
| Scale | Multiplies two vectors component-wise. |
Operators
Operator | Description |
|---|---|
| operator + | Adds two vectors. |
| operator / | Divides a vector by a number. |
| operator == | Returns true if two vectors are approximately equal. |
| Vector4 | Converts a Vector2 to a Vector4. |
| Vector2 | Converts a Vector4 to a Vector2. |
| Vector3 | Converts a Vector4 to a Vector3. |
| operator * | Multiplies a number by a vector. |
| operator - | Subtracts one vector from another. |