Clamp - OuterRimStudios/Utilities GitHub Wiki
MathUtilities.Clamp
public static Vector3 Clamp(Vector3 vector, float clampValue)
Parameters
vector The Vector3 to be clamped.
clampValue The value at which the Vector3 will be clamped.
Returns
Vector3 the Vector3 after being clamped within the clamp range.
Description
Clamps all axes of the entered Vector3 between the negative and positive of the entered clamp value.
using UnityEngine;
using OuterRimStudios.Utilities;
public class ExampleClass : MonoBehaviour
{
void Start()
{
transform.position = MathUtilites.Clamp(transform.position, 50); //Clamps the transform's position between -50/50 on all axes.
}
}
public static Vector3 Clamp(Vector3 vector, float minClampValue, float maxClampValue)
Parameters
vector The Vector3 to be clamped.
minClampValue The minimum value at which the Vector3 will be clamped.
maxClampValue The maximum value at which the Vector3 will be clamped.
Returns
Vector3 the Vector3 after being clamped between the minClampValue and maxClampValue.
Description
Clamps all axes of the entered Vector3 between the minClampValue and the maxClampValue.
using UnityEngine;
using OuterRimStudios.Utilities;
public class ExampleClass : MonoBehaviour
{
void Start()
{
transform.position = MathUtilites.Clamp(transform.position, -25, 50); //Clamps the transform's position between -25/50 on all axes.
}
}