Beispiel #1
0
    void Kick()
    {
        FlipSquare square = CheckForSquare();

        if (square)
        {
            square.GetKicked(playerDirection);
        }
    }
Beispiel #2
0
    FlipSquare CheckForSquare()
    {
        Vector2 leftBottom = new Vector2(bounds.center.x, bounds.center.y) +
                             (Vector2.down * bounds.extents) + (Vector2.left * bounds.extents);
        Vector2 rightBottom = new Vector2(bounds.center.x, bounds.center.y) +
                              (Vector2.down * bounds.extents) + (Vector2.right * bounds.extents);

        for (int i = 0; i < 10; i++)
        {
            Vector2 rayOrigin = (playerDirection == 1 ? rightBottom : leftBottom) + Vector2.up * i * (bounds.size.x / 10);

            RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * playerDirection, kickDistance, squareMask);

            if (hit)
            {
                if (hit.collider != null)
                {
                    FlipSquare square = hit.collider.gameObject.GetComponent <FlipSquare>() as FlipSquare;
                    return(square);
                }
            }
        }
        return(null);
    }