Skip to content

Instantly share code, notes, and snippets.

@Volorf
Last active January 7, 2024 19:41
Show Gist options
  • Save Volorf/8518e9b8873b35ad6e60ece2ad72fbb2 to your computer and use it in GitHub Desktop.
Save Volorf/8518e9b8873b35ad6e60ece2ad72fbb2 to your computer and use it in GitHub Desktop.
Remap extension method for Float Value
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