UnityEssentials
Small but useful tools and features for Unity
FloatExtensions.cs
Go to the documentation of this file.
1 namespace UnityEngine
2 {
6  public static class FloatExtensions
7  {
15  public static float Loop(this float floatToBeLooped, float exclusiveMaximum, float inclusiveMinimum = 0f, float variancePerStep = 1f)
16  {
17  float returnInt = floatToBeLooped + variancePerStep;
18  if (returnInt >= exclusiveMaximum)
19  returnInt = inclusiveMinimum;
20  return returnInt;
21  }
22 
31  public static float Map(this float value, float originalRangeMin, float originalRangeMax, float newRangeMin = 0f, float newRangeMax = 1f)
32  {
33  return ((value - originalRangeMin) / (originalRangeMax - originalRangeMin) * (newRangeMax - newRangeMin)) + newRangeMin;
34  }
35  }
36 }
Extensions for float
static float Map(this float value, float originalRangeMin, float originalRangeMax, float newRangeMin=0f, float newRangeMax=1f)
Maps the value from one range to another range.
static float Loop(this float floatToBeLooped, float exclusiveMaximum, float inclusiveMinimum=0f, float variancePerStep=1f)
Loops the float between a minimum and maximum.