Пример #1
0
    public void VerticalAttack()
    {
        UpdateRaycastOrigins();
        // float originalMoveAmountX = moveAmount.x;
        Collider2D           otherCollider   = null;
        HashSet <Collider2D> attackedEnemies = new HashSet <Collider2D>();

        float directionY = Mathf.Sign(attack.direction.y);

        for (int i = 0; i < verticalRayCount; i++)
        {
            Vector2 rayOrigin = (directionY == -1) ? raycastOrigins.bottomLeft : raycastOrigins.topLeft;
            rayOrigin += Vector2.right * (verticalRaySpacing * i);
            RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, range, collisionMask);

            Debug.DrawRay(rayOrigin, Vector2.up * directionY * range, Color.yellow);

            if (hit)
            {
                if (hit.distance == 0)
                {
                    continue;
                }

                otherCollider = hit.collider;
            }

            if (otherCollider != null && otherCollider.gameObject != this.gameObject && !attackedEnemies.Contains(otherCollider)) // && otherCollider.tag == "Pushable"
            {
                attackedEnemies.Add(otherCollider);
                Destructable destructable = otherCollider.gameObject.GetComponent <Destructable>();
                if (destructable)
                {
                    destructable.Damage(damage);
                }


                if (otherCollider.tag == "Pushable")
                {
                    PushableObject pushable = otherCollider.gameObject.GetComponent <PushableObject>();
                    pushable.Launch(new Vector2(pushForce.x, pushForce.y * directionY));
                }
            }
        }
    }