How can i make the child collider turn off and on instead of the parent collider?

using UnityEngine;

public class ZGruntAttack : MonoBehaviour {

public float timeBetweenAttacks = 0.5f;     // The time in seconds between each attack.
public int attackDamage = 10;               // The amount of health taken away per attack.

Animator anim;                              // Reference to the animator component.
GameObject player;                          // Reference to the player GameObject.
PlayerHealth playerHealth;                  // Reference to the player's health.
EnemyHealth enemyHealth;                    // Reference to this enemy's health.
bool playerInRange;                         // Whether player is within the trigger collider and can be attacked.
float timer;                                // Timer for counting up to the next attack.
int runHash = Animator.StringToHash("Run");
private CapsuleCollider weaponCollider;

// UnityEngine.AI.NavMeshAgent nav;

void Awake ()
{
    // Setting up the references.
    player = GameObject.FindGameObjectWithTag ("Player");
    playerHealth = player.GetComponent <PlayerHealth> ();
    enemyHealth = GetComponent<EnemyHealth>();
    anim = GetComponent <Animator> ();
    weaponCollider = GetComponentInChildren<CapsuleCollider> ();
}

/// Start is called on the frame when a script is enabled just before
void Start() {
    

}

void OnTriggerEnter (Collider other)
{
    // If the entering collider is the player...
    if(other.gameObject == player)
    {
        // ... the player is in range.
        playerInRange = true;
    }
}

void OnTriggerExit (Collider other)
{
    // If the exiting collider is the player...
    if(other.gameObject == player)
    {
        // ... the player is no longer in range.
        playerInRange = false;
        anim.SetTrigger (runHash);
    }
}

void Update ()
{
    // Add the time since Update was last called to the timer.
    timer += Time.deltaTime;

    // If the timer exceeds the time between attacks, the player is in range and this enemy is alive...
    if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0)
    {
        // ... attack.
        Attack ();

    }

    // If the player has zero or less health...
    if(playerHealth.currentHealth <= 0)
    {
        // ... tell the animator the player is dead.
        anim.SetTrigger ("PlayerDied");
    }
}

void Attack () {

    // Reset the timer.
    timer = 0f;

    // If the player has health to lose...
    if(playerHealth.currentHealth > 0)
    {
        // ... damage the player.

// playerHealth.TakeDamage (attackDamage);
anim.Play(“Attack”,-1,0f);
}
}

public void EnemyBeginAttack () {
    weaponCollider.enabled = true;
}

public void EnemyEndAttack () {
    weaponCollider.enabled = false;
}

}

dont use if(other.gameObject == player) use if(other.tag == "playerChild")
and change the tag of the child of the player you want to playerChild.
you do this by clicking any gameobject and look at the inspector, you’ll see below is the Tag: and the Layer:
click the Tag and click the Add Tag in the Tag dropdown, click the Plus sign and add the “playerChild” and click save.
now you’re not done yet… you just created a new tag but you didn’t apply it to the child that you want.

now find the child you want and click the tag… and look for the playerChild tag or any tagname you want. as long as its the same in the codes if(other.tag == “playerChild”)`