int Item { get; set; }

book_4_sparkGenerated
code_blocksInput

Description

The Item property of the Vector2Int struct provides indexed access to the components of the vector. This property allows you to get or set the value of the vector's components using an index, where index 0 corresponds to the X component and index 1 corresponds to the Y component.

Usage

Use the Item property to access or modify the X or Y components of a Vector2Int instance by index. This is particularly useful when you need to iterate over the components of the vector or when you want to write generic code that works with both components without explicitly referencing them by name.

Example

Vector2Int vector = new Vector2Int(3, 4);

// Accessing components using the Item property
int xComponent = vector[0]; // Equivalent to vector.x
int yComponent = vector[1]; // Equivalent to vector.y

// Modifying components using the Item property
vector[0] = 5; // Sets the x component to 5
vector[1] = 6; // Sets the y component to 6

// Output the modified vector
// vector is now (5, 6)