Last active
January 7, 2024 19:41
-
-
Save Volorf/8518e9b8873b35ad6e60ece2ad72fbb2 to your computer and use it in GitHub Desktop.
Remap extension method for Float Value
This file contains hidden or 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
using UnityEngine; | |
public static class ExtensionMethods | |
{ | |
public static float Remap (this float from, float fromMin, float fromMax, float toMin, float toMax) | |
{ | |
float fromAbs = from - fromMin; | |
float fromMaxAbs = fromMax - fromMin; | |
float normal = fromAbs / fromMaxAbs; | |
float toMaxAbs = toMax - toMin; | |
float toAbs = toMaxAbs * normal; | |
float to = toAbs + toMin; | |
return to; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment