Skip to content

Instantly share code, notes, and snippets.

@kiranmaya
Created May 16, 2017 12:01
Show Gist options
  • Save kiranmaya/a859f25f042dd58f36f7abd85d134f72 to your computer and use it in GitHub Desktop.
Save kiranmaya/a859f25f042dd58f36f7abd85d134f72 to your computer and use it in GitHub Desktop.
convert from one range to another equivalent range
float extension
public static float Remap(this float value, float from1, float to1, float from2, float to2,bool isClamped= false)
{
if(isClamped)
{
value = Mathf.Clamp(value,from1,to1);
}
return (value - from1) / (to1 - from1) * (to2 - from2) + from2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment