Map Value - OuterRimStudios/Utilities GitHub Wiki

MathUtilities.MapValue

public static float MapValue(float newRangeMin, float newRangeMax, float currentRangeMin, float currentRangeMax, float value)

Parameters

newRangeMin The minimum value of the range within which the value will be mapped.

newRangeMax The maximum value of the range within which the value will be mapped.

currentRangeMin The minimum value of the range that the value currently exists.

currentRangeMax The maximum value of the range that the value currently exists.

value The value to be mapped within the new range.

Returns

float input value converted to a value within new range.

Description

Maps a value that exists between a range to be within a new range.

using UnityEngine;
using OuterRimStudios.Utilities;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        float mappedValue = MathUtilites.MapValue(0, 1, 0, 50, 25);    //Returns 0.5
    }
}

MathUtilities.MapValue01

public static float MapValue01(float currentRangeMin, float currentRangeMax, float value)

Parameters

currentRangeMin The minimum value of the range that the value currently exists.

currentRangeMax The maximum value of the range that the value currently exists.

value The value to be mapped within the new range.

Returns

float input value converted to a value within a 0 to 1 range.

Description

Maps a value that exists between a range to be within a 0 to 1 range.

using UnityEngine;
using OuterRimStudios.Utilities;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        float mappedValue = MathUtilites.MapValue(0, 100, 50);    //Returns 0.5
    }
}