Created
April 28, 2020 17:54
-
-
Save CRodriguez25/ff5a871ba8cdb2bb45c8d84a2d5d8a84 to your computer and use it in GitHub Desktop.
A couple of useful Vector extension methods for creating Vectors based on other vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ExtensionMethods | |
{ | |
public static Vector2 CopyWith(this Vector2 vector, float? x = null, float? y = null) | |
{ | |
return new Vector2(x ?? vector.x, y ?? vector.y); | |
} | |
public static Vector3 CopyWith(this Vector3 vector, float? x = null, float? y = null, float? z = null) | |
{ | |
return new Vector3(x ?? vector.x, y ?? vector.y, z ?? vector.z); | |
} | |
} | |
// Example Usage: transform.localPosition = targetPosition.CopyWith(x: targetPosition.x + 30, y: targetPosition.y - 15); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment