Vector3 WithZ( float z )

book_4_sparkGenerated
code_blocksInput

Description

The WithZ method of the Vector3 struct returns a new Vector3 instance with the Z component set to the specified value, while keeping the X and Y components unchanged. This method is useful when you need to modify only the Z component of a vector without affecting the other components.

Usage

To use the WithZ method, call it on an existing Vector3 instance and pass the desired Z value as a parameter. The method will return a new Vector3 with the updated Z component.

Example

Vector3 originalVector = new Vector3(1.0f, 2.0f, 3.0f);
Vector3 updatedVector = originalVector.WithZ(5.0f);
// updatedVector is now (1.0, 2.0, 5.0)