Description
The WithX
method of the Vector2
struct returns a new Vector2
instance with the X component set to the specified value, while keeping the Y component unchanged. 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 will return a new Vector2
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)