Exemplo n.º 1
0
    public bool IsBlocked(GameObject sq)
    {
        bool blocked = false;

        Vector3 height = 0.01f * transform.up;

        RaycastHit hit;

        //this is the theretical distance between points:

        Vector3 direction = piecemovScript.selectedPiece.transform.position - sq.transform.position;
        float   thDist    = (direction).magnitude;

        //need to enable colliders to check the raycasts of the opposite pieces
        piecemovScript.enablePieces(1 - piecemovScript.playerTurn);

        // Does the ray intersect any objects excluding the player layer
        if (Physics.Raycast(sq.transform.position + height, direction, out hit, Mathf.Infinity))
        {
            if (Mathf.Abs(thDist - hit.distance) < 0.1f)
            {
                blocked = false;
            }
            else
            {
                blocked = true;
            }
        }

        //disable colliders again
        piecemovScript.disablePieces(1 - piecemovScript.playerTurn);

        return(blocked);
    }