Exemple #1
0
        /// <summary>
        /// When state is not <see cref="State.Inactive"/>, checks for an overlap with a hurtbox and calls CollidedWith in <see cref="responder"/>.
        /// </summary>
        public virtual void UpdateHitbox()
        {
            // Cancel if Inactive
            if (hbState == State.Inactive)
            {
                return;
            }

            // Check Hitbox
            Collider2D[] colliders = GetOverlappingColliders();

            // Perform interaction on hit
            for (int i = 0; i < colliders.Length; i++)
            {
                responder?.Hit(colliders[i]);
            }
        }
        /// <summary>
        /// When state is not <see cref="State.Inactive"/>, checks for an overlap with a hurtbox and calls CollidedWith in <see cref="_responder"/>.
        /// </summary>
        public void UpdateHitbox()
        {
            // Cancel if Inactive
            if (_state == State.Inactive)
            {
                return;
            }

            // Check Hitbox
            Collider[] colliders = GetOverlappingHurtboxes();

            // Perform interaction on hit
            for (int i = 0; i < colliders.Length; i++)
            {
                Collider collider = colliders[i];
                _responder?.Hit(collider);
            }
        }
Exemple #3
0
    public void CheckCollision()
    {
        if (state == ColliderState.CLOSED)
        {
            return;
        }
        Collider2D[] colliders  = new Collider2D[maxTargets];
        int          collisions = Physics2D.OverlapBox((Vector2)trans.position + offset, size, 0f, mask, colliders);

        for (int i = 0; i < collisions; i++)
        {
            Collider2D coll = colliders[i];
            if (responder != null)
            {
                responder.Hit(coll, act);
            }
        }
        state = collisions > 0 ? ColliderState.COLLIDING : ColliderState.OPEN;
    }