Mathf.Abs絶対値
指定されたパラメータfの絶対値を返します
Debug.Log(Mathf.Abs(-3)); // Prints 3
Mathf。おおよそおおよそ
aとbが類似している場合は、trueを返します。
if (Mathf.Approximately(1.0f, 10.0f / 10.0f)) //sometimes return true;
Mathf.Ceil 向上取整
Debug.Log(Mathf.Ceil(10.0F)); // Prints 10
Debug.Log(Mathf.Ceil(10.2F)); // Prints 11
Debug.Log(Mathf.Ceil(10.7F)); // Prints 11
Debug.Log(Mathf.Ceil(-10.0F)); // Prints -10
Debug.Log(Mathf.Ceil(-10.2F)); // Prints -10
Debug.Log(Mathf.Ceil(-10.7F)); // Prints -10
Mathf.Floorの切り捨て
Debug.Log(Mathf.Floor(10.0F)); // Prints 10
Debug.Log(Mathf.Floor(10.2F)); // Prints 10
Debug.Log(Mathf.Floor(10.7F)); // Prints 10
Debug.Log(Mathf.Floor(-10.0F)); // Prints -10
Debug.Log(Mathf.Floor(-10.2F)); // Prints -11
Debug.Log(Mathf.Floor(-10.7F)); // Prints -11
Mathf。ラウンドラウンド
数値の終わりが.5であるため、偶数か奇数かに関係なく、2つの整数の間にある場合は、偶数が返されます。
Debug.Log(Mathf.Round(10.5f)); //Prints 10
Debug.Log(Mathf.Round(11.5f)); //Prints 12
Debug.Log(Mathf.Round(-10.5f)); //Prints -10
Debug.Log(Mathf.Round(-11.5f)); //Prints -12
Mathf.Max最大/Mathf.Min最小
Debug.Log(Mathf.Max(1,3,5,7,9)); //Prints 9
Debug.Log(Mathf.Min(1,3,5,7,9)); //Prints 1
Mathf.Clampの制限
値の値を最小と最大の間に制限します。値が最小未満の場合は、最小を返します。値が最大より大きい場合は最大を返し、そうでない場合は値を返します
float min = 1;
float max = 2;
Debug.Log(Mathf.Clamp(0.5, min, max)); // Prints 1
Debug.Log(Mathf.Clamp(1.5, min, max)); // Prints 1.5
Mathf.Clamp01制限0〜1
値の値を0から1の間に制限し、値を返します。
Debug.Log(Mathf.Clamp01(0.5)); // Prints 0.5
Debug.Log(Mathf.Clamp01(1.5)); // Prints 1
Mathf.Lerp補間/Mathf.InverseLerp逆補間
debug.Log(Mathf.Lerp(50, 100, 0.5)); //Prints 75
debug.Log(Mathf.InverseLerp (50, 100, 75)); //Prints 0.5
debug.Log(Mathf.Lerp(-50, 50, 0.75)); //Prints 25
debug.Log(Mathf.InverseLerp (-50, 50, 25)); //Prints 0.75
debug.Log(Mathf.Lerp(0, 2, -1)); //Prints 0
debug.Log(Mathf.Lerp(0, -2, 1)); //Prints -2
debug.Log(Mathf.LerpUnclamped(0,2,-1)); //Prints -2
debug.Log(Mathf.InverseLerp (0, 2, 3)); //Prints 1
Mathf.Lerp(a、b、t)=(b-a)* Mathf.clamp01(t)+ a; || Mathf.clamp((b-a)* t + a、a、b);
Mathf.InverseLerp(a、b、t)= Mathf.clamp01((t-a)/(b-a));
Mathf.Lerp(0、b、t)= Mathf.clamp01(t)* b;
Mathf.InverseLerp(0、b、t)= Mathf.clamp01(t / b);
Mathf.MoveTowardsに移動します
現在の値を変更して目標値に近づけます。速度はmaxDeltaを超えません。
void Update()
{
currStrength = Mathf.MoveTowards(currStrength, maxStrength, recoveryRate * Time.deltaTime);
}
Mathf.Powパワー/Mathf.Sqrtスクエア
debug.Log(Mathf.Pow(2, 3)); //2^3 = 8
debug.Log(Mathf.Sqrt(9)); //开方9 =3
Mathf.PingPong / Mathf.Repeat
ピンポン値t、戻り値は0と長さの間を行ったり来たりします。
ループ値tは、長さより大きくなることも、0より小さいこともありません。
void Update()
{
// Set the x position to loop between 0 and 3
transform.position = new Vector3(Mathf.PingPong(Time.time, 3), 0,0);
transform.position = new Vector3(Mathf.Repeat(Time.time, 3), 0,0);
}
注:Time.deltaTimeではなくTime.timeです!!
for (int i = 0; i < 5; i++)
{
Debug.Log(Mathf.PingPong(i,3));
//0123210123210123210...
}
forループも使用できます
Mathf.Signシンボル
Debug.Log(Mathf.Sign(-10)); //Prints -1
Debug.Log(Mathf.Sign(0)); //Prints 1
Debug.Log(Mathf.Sign(10)); //Prints 1
Mathfではなく演算子ですが、それでも書き留めます
bool yes = true;
debug.Log(yes ? 50 : 3); //Prints 50
bool no = false;
debug.Log(no ? 30 : 5); //Prints 5