How do I mute one sound source using another?

I have a cube which emanates sound. I want to make it so that when my First-person camera controller passes through another cube, the sound of the first cube mutes.

The challenge I’m facing here is that I think I need to place a script on the second cube that points to and controls the mute controls on the first cube.

This seems pretty basic, but I don’t know the way forward. I’ve tried using the Accessing Other Game Objects tutorial and was able to locate the first cube from the second using a tag. However, I’m not entirely sure where to go from here or whether that was even the right approach to begin with.

Any help would be appreciated! For what it’s worth, I’m using C Sharp but am open to using either JS or CS for this.

thanks

-g

Put a script on your character that keeps a reference to the current playing source. When colliding with the new source, stop the old one, start the new one, and keep a reference to the new one instead.

private AudioSource currentlyPlaying = null;

void OnTriggerEnter(Collider other) {
    AudioSource newSource = other.GetComponent<AudioSource>();

    // if collided with an object that has audio source
    if (newSource != null) {
        // disable previous source if exists
        if (currentlyPlaying != null) {
            currentlyPlaying.Stop();
        }

        // activate new source and keep reference
        currentlyPlaying = newSource;
        currentlyPlaying.Play();
    }
}