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