Clamp Angle - CSharp System

CSharp examples for System:Math Geometry

Description

Clamp Angle

Demo Code


using UnityEngine;

public class Main{
        public static float ClampAngle(float angle, float min, float max)
    {//ww w. j  a  v  a2s .c  om
        do
        {
            if (angle < -360)
                angle += 360;
            if (angle > 360)
                angle -= 360;

        } while (angle < -360 || angle > 360);

        return Mathf.Clamp(angle, min, max);
    }
}

Related Tutorials