public float Map(float OldMin, float OldMax, float NewMin, float NewMax, float OldValue) { float OldRange = (OldMax - OldMin); float NewRange = (NewMax - NewMin); float NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin; if (NewValue < NewMin) { return NewMin; } if (NewValue > NewMax) { return NewMax; } return NewValue; }