Beispiel #1
0
    public bool CheckNeighbors()
    {
        int     isPopulated  = 0;
        int     isValid      = 0;
        Vector3 cubePosition = HexMath.AxialToCube(HexMath.PixelToHex(transform.position));

        RaycastHit hit;
        int        direction;

        for (int i = 0; i < 6; i++)
        {
            if (Physics.Raycast(HexMath.HexToPixel(HexMath.CubeToAxial(cubePosition + HexMath.direction[i])) + Vector3.forward, Vector3.back, out hit))
            {
                Hex hex = hit.collider.GetComponent <Hex>();
                if (hex != null)
                {
                    isPopulated++;

                    direction = i + 3;
                    if (direction > 5)
                    {
                        direction -= 6;
                    }

                    if (hex.CheckValidity(direction, fieldType[i]))
                    {
                        isValid++;
                    }
                }
            }
        }

        return((isPopulated != 0) && (isPopulated == isValid));
    }