Skip to content

Instantly share code, notes, and snippets.

@MathiasYde
Created December 19, 2021 17:43
Show Gist options
  • Save MathiasYde/356b9a39d47f4e0a7ce82311f8ccb75b to your computer and use it in GitHub Desktop.
Save MathiasYde/356b9a39d47f4e0a7ce82311f8ccb75b to your computer and use it in GitHub Desktop.
Unity MinMax datamodel
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