Beispiel #1
0
    public bool IsAlignedTo(RoomControl siblingRoom)
    {
        bool  aligned     = false;
        var   thiBc       = GetComponent <BoxCollider2D>();
        float thisExtX    = thiBc.bounds.extents.x;
        float thisExtY    = thiBc.bounds.extents.y;
        var   siblingBc   = siblingRoom.GetComponent <BoxCollider2D>();
        float siblingExtX = siblingBc.bounds.extents.x;
        float siblingExtY = siblingBc.bounds.extents.y;

        aligned = (Mathf.Approximately(transform.position.x, siblingRoom.transform.position.x) &&
                   Mathf.Approximately(Mathf.Abs(transform.position.y - siblingRoom.transform.position.y),
                                       thisExtY + siblingExtY)) ||
                  (Mathf.Approximately(transform.position.y, siblingRoom.transform.position.y) &&
                   Mathf.Approximately(Mathf.Abs(transform.position.x - siblingRoom.transform.position.x),
                                       thisExtX + siblingExtX));
        return(aligned);
    }