How can I make my character crouch and attack?

I have this code for player combat. I have it set to attack and play an animation then detect enemy colliders in the box. I have two separate hitEnemies for when chrouching and not. I can’t find a way to get my character to crouch and attack and get the debug.log to activate.

Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Player_combat : MonoBehaviour
{
 
    public Animator animator;
 
    public Transform attackPoint;
    public Vector2 swordSize;
    public int swordCollider = 5;
    public int swordCollider2 = 5;
    public LayerMask enemyLayers;
    public Transform attackPoint2;
    public Vector2 swordSize2;
 
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.N))
        {
            Attack();
        }
    }
 
void Attack()
    {
        //Play animation
        animator.SetTrigger("Attack");
 
        //Detect enemies in range of box
        Collider2D[] hitEnemies = Physics2D.OverlapBoxAll(attackPoint.position, swordSize, swordCollider, enemyLayers);
        Collider2D[] hitEnemies2 = Physics2D.OverlapBoxAll(attackPoint2.position, swordSize2, swordCollider, enemyLayers);
        //Damage them
        foreach (Collider2D enemy in hitEnemies)
        {
            Debug.Log("We hit" + enemy.name);
        }
        foreach (Collider2D enemy in hitEnemies2)
        if (Input.GetButtonDown("Crouch"))
        {
            Debug.Log("We hit" + enemy.name);
        }
    }
    private void OnDrawGizmosSelected()
    {
        if (attackPoint == null)
            return;
        Gizmos.DrawWireCube(attackPoint.position, swordSize);
        if (attackPoint2 == null)
            return;
        Gizmos.DrawWireCube(attackPoint2.position, swordSize2);
    }
 
}

I have this code for player combat. I have it set to attack and play an animation then detect enemy colliders in the box. I have two separate hitEnemies for when chrouching and not. I can’t find a way to get my character to crouch and attack and get the debug.log to activate.

I think you have two types of key actions that are conflicting the coding of the player to crouch.

One telling to crouch by pressing Key.Code N

Then, you check with a button “Crouch”

I do not think you need the second if statement with “Crouch” since method Attack() is inside Update() unless KeyCode.N is different than crouch.

Just take out the second if statement with “Crouch”

 if (Input.GetButtonDown("Crouch"))

if you have two different key actions.
You are going to need to separate the two key actions or else it will not work. You are not pressing one button. You are pressing two buttons. So you have to code it separately.

Just make Attack() methods Attack1() and Attack2() with different key actions KeyCode.N

Good Luck!