示例#1
0
    int GetBarIndex(Vector3 position, TFRAxisCompare axis)
    {
        int index = 0;

        if (bars.Length == 0)
        {
            return(index);
        }

        float   pos = GetVectorAxis(position, axis);
        float   min = Mathf.Infinity;
        float   barPos;
        Vector3 p;

        for (int i = 0; i < bars.Length; i++)
        {
            p      = bars[i].transform.position;
            barPos = GetVectorAxis(p, axis);
            float diff = Mathf.Abs(pos - barPos);
            if (diff < min)
            {
                min   = diff;
                index = i;
            }
        }
        return(index);
    }
示例#2
0
 float GetVectorAxis(Vector3 v, TFRAxisCompare a)
 {
     if (a == TFRAxisCompare.X)
     {
         return(v.x);
     }
     if (a == TFRAxisCompare.Y)
     {
         return(v.y);
     }
     return(v.z);
 }