Vector3 WithZ( float z )

book_4_sparkGenerated
code_blocksInput

Description

The WithZ method of the Vector3 struct allows you to create a new Vector3 instance with a specified Z component, 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 new Z value as a parameter. The method returns a new Vector3 instance with the updated Z component.

Example

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