UnityEngine.Mathf.Abs C# (CSharp) Method

Abs() public static method

public static Abs ( float f ) : float
f float
return float
        public static float Abs(float f)
        {
            return Math.Abs(f);
        }

Same methods

Mathf::Abs ( int value ) : int

Usage Example

コード例 #1
0
    static private Dir vec3ToDir(Vec3 pos)
    {
        /* XXX: Only check axis X and Z */
        int[] axisOrder = { 0, 2 };
        Dir[,] perAxis =
        {
            { Dir.Left,   Dir.Right },
            { Dir.Bottom, Dir.Top   },
            { Dir.Back,   Dir.Front },
        };
        float absDist = 0.0f;
        Dir   d       = Dir.None;

        /* Select the direction of the axis with the greater distance, so the
         * entity will follow the last position of the targeted object */
        for (int i = 0; i < axisOrder.Length; i++)
        {
            int axis = axisOrder[i];
            if (Math.Abs(pos[axis]) > absDist)
            {
                absDist = Math.Abs(pos[axis]);
                if (pos[axis] < 0)
                {
                    d = perAxis[axis, 0];
                }
                else if (pos[axis] > 0)
                {
                    d = perAxis[axis, 1];
                }
            }
        }

        return(d);
    }
All Usage Examples Of UnityEngine.Mathf::Abs