Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

Mathf.Max

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 Single Max(Single a, Single b);

Declaration

public static Single Max(params Single[] values);

Parameters

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

Returns

Single Greatest value found between all compared values.

Description

Returns the maximum of two or more values.

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

Additional resources: Min.

using UnityEngine;

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

Declaration

public static Int32 Max(Int32 a, Int32 b);

Declaration

public static Int32 Max(params Int32[] values);

Parameters

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

Returns

Int32 Greatest value found between all compared values.

Description

Returns the maximum of two or more values.

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

Additional resources: Min.

using UnityEngine;

public class ScriptExample : MonoBehaviour { void Start() { // Prints 2147483647 Debug.Log(Mathf.Max(0, int.MaxValue)); // Prints 0 Debug.Log(Mathf.Max(0, int.MinValue)); // Prints 2147483647 Debug.Log(Mathf.Max(int.MinValue, int.MaxValue)); // Prints 10 Debug.Log(Mathf.Max(0, 1, 5, -1, 8, 10)); } }