/// Remaps the given value from one range to another. Source: GitHub /// The value to remap. /// Minimum range of the source value. /// Maximum range of the source value. /// Minimum range of the return value. /// Maximum range of the return value. public float RemapValueRange(float source, float sourceMin, float sourceMax, float targetMin, float targetMax) { source = Mathf.Clamp(source, sourceMin, sourceMax); // ensure that source value is in the given range or it can output higher/lower values than requested value range! return (source - sourceMin) * (targetMax - targetMin) / (sourceMax - sourceMin) + targetMin; } /// Remaps the given value from (0 -> 1) range to requested range. Source: GitHub /// The value to remap. /// Minimum range of the return value. /// Maximum range of the return value. public float RemapValueRangeFrom01(float source, float targetMin, float targetMax) { return RemapValueRange(source, 0, 1, targetMin, targetMax); } /// Remaps the given value from the given range to (0 -> 1) range. Source: GitHub /// The value to remap. /// Minimum range of the source value. /// Maximum range of the source value. public float RemapValueRangeTo01(float source, float sourceMin, float sourceMax) { return RemapValueRange(source, sourceMin, sourceMax, 0, 1); }