How to select BoxColliders of children and disable them?

Hello.

I’m trying to make my project recognize the Box Colliders of all of its children and enable them during the specific steps of a walking animation for one second, then disable them again, but Unity cannot find what I’m asking of it (NullReferenceException). Granted, the sound works perfectly fine during the trigger, unless the player/ camera happens to be facing away from what’s walking; but it cannot find the colliders at all.

Here’s the erroneous code I have. It’s simple, but I’m new as well:

var audioVolume = 1.0;
var collisionSoundEffect : AudioClip;

function playSound() {

audio.volume = audioVolume;
audio.clip = collisionSoundEffect;
audio.Play();

gameObject.GetComponentsInChildren(BoxCollider).collider.enabled = true;
yield WaitForSeconds(1);
gameObject.GetComponentsInChildren(BoxCollider).collider.enabled = false;
}

I don’t fully understand javascript syntax (I use c#), however

GetComponentsInChildren

returns an array of BoxCollider(s). So ideally you want to store that array in a variable then loop through each BoxCollider and enable / disable it.

I’m guessing the exception is due to you trying to access the ‘collider’ property on an array (which doesn’t exist).

One other thought is that your collider is not on the child, so perhaps you just want to use GetComponent instead of GetComponentsInChildren.