Description
The WithX
method of the Vector2
struct allows you to create a new Vector2
instance with a specified X component, while retaining the original Y component of the vector. This method is useful when you need to modify only the X component of a vector without affecting its Y component.
Usage
To use the WithX
method, call it on an existing Vector2
instance and pass the new X value as a parameter. The method returns a new Vector2
instance with the updated X value.
Example
Vector2 originalVector = new Vector2(3.0f, 4.0f);
Vector2 newVector = originalVector.WithX(5.0f);
// newVector is now (5.0f, 4.0f)