Created
December 19, 2021 17:43
-
-
Save MathiasYde/356b9a39d47f4e0a7ce82311f8ccb75b to your computer and use it in GitHub Desktop.
Unity MinMax datamodel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[System.Serializable] | |
public struct MinMax { | |
public float min; | |
public float max; | |
public MinMax(float min, float max) { | |
this.min = min; | |
this.max = max; | |
} | |
/// <summary> | |
/// Clamps the given value between min and max | |
/// </summary> | |
public float Clamp(float value) { | |
return Mathf.Clamp(value, this.min, this.max); | |
} | |
/// <summary> | |
/// Returns true if the given value is within min and max | |
/// </summary> | |
public bool Within(float value) { | |
return value > this.min && value < this.max; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment