Version: Unity 6.2 Alpha (6000.2)
LanguageEnglish
  • C#

Mathf.Min

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Declaration

public static float Min(float a, float b);

Declaration

public static float Min(params float[] values);

Parameters

a First value to compare.
b Second value to compare.
values Array of values to compare.

Returns

float Smallest value found between all compared values.

Description

Returns the minimum of two or more values.

The resulting value will be the input value closest to '-Mathf.Infinity'.

Additional resources: Max.

using UnityEngine;

public class ScriptExample : MonoBehaviour { void Start() { // Prints 0 Debug.Log(Mathf.Min(0, Mathf.Infinity)); // Prints -Inifnity Debug.Log(Mathf.Min(0, -Mathf.Infinity)); // Prints -Infinity Debug.Log(Mathf.Min(-Mathf.Infinity, Mathf.Infinity)); // Prints -1 Debug.Log(Mathf.Min(0, 1, 5, -1, 8, 10)); } }

Declaration

public static int Min(int a, int b);

Declaration

public static int Min(params int[] values);

Parameters

a First value to compare.
b Second value to compare.
values Array of values to compare.

Returns

int Smallest value found between all compared values.

Description

Returns the minimum of two or more values.

The resulting value will be the input value closest to 'int.MinValue'.

Additional resources: Max.

using UnityEngine;

public class ScriptExample : MonoBehaviour { void Start() { // Prints 0 Debug.Log(Mathf.Min(0, int.MaxValue)); // Prints -2147483648 Debug.Log(Mathf.Min(0, int.MinValue)); // Prints -2147483648 Debug.Log(Mathf.Min(int.MinValue, int.MaxValue)); // Prints -1 Debug.Log(Mathf.Min(0, 1, 5, -1, 8, 10)); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961