Description
The Item
property of the Vector3
struct allows you to access or modify the individual components of the vector using an index. This property is useful for iterating over the components of the vector in a loop or when you need to dynamically access a component based on a condition.
Usage
Use the Item
property to access the x
, y
, or z
components of a Vector3
instance by index. The index values are as follows:
0
for the x
component
1
for the y
component
2
for the z
component
Example usage:
Vector3 vector = new Vector3(1.0f, 2.0f, 3.0f);
float xComponent = vector[0]; // Access x component
vector[1] = 5.0f; // Modify y component
Example
Vector3 vector = new Vector3(1.0f, 2.0f, 3.0f);
// Accessing components using the Item property
float x = vector[0]; // x is 1.0f
float y = vector[1]; // y is 2.0f
float z = vector[2]; // z is 3.0f
// Modifying components using the Item property
vector[0] = 4.0f; // x is now 4.0f
vector[1] = 5.0f; // y is now 5.0f
vector[2] = 6.0f; // z is now 6.0f