Character walking sound controller.isgrounded problems

Ahoy.

I recently started fiddling with Unity/C#. After a few tutorials, I’ve started expanding a bit on the scripts currently in my little FPS shooter.
Im now working on adding a walking sound to my scripts. After some searching I found some examples and added a few lines to my charactercontroller script.

In the same Answers thread, it mentioned to add a ‘controller.isGrounded’ to check the character isn’t in the air jumping.

I’ve tried many combinations, and most of them work - partially. When I stop walking, the sound stops. When I jump, the sound stops. If I keep a button pressed during the jump though, the sound won’t continue after my jump unless I tap another movement key, or re-tap the one I’m currently pressing.

if ( characterController.isGrounded && (Input.GetButtonDown( "Horizontal") || Input.GetButtonDown ( "Vertical" )) && !audio.isPlaying) {
		audio.Play();
		}
		else if ( !characterController.isGrounded || !Input.GetButton ( "Horizontal" ) && !Input.GetButton( "Vertical" ) && audio.isPlaying ){
    	audio.Stop (); 
		}

(And yes, I should probably clean the code a bit, and be more consistent on where to use enter/space etc.)

Many thanks in advance!

" If I keep a button pressed during the jump though, the sound won’t continue after my jump unless I tap another movement key, or re-tap the one I’m currently pressing."

And this is how the Input.GetButtonDown works Unity - Scripting API: Input.GetButtonDown

You need to call this function from the Update function, since the state
gets reset each frame. It will not
return true until the user has
released the key and pressed it
again.

So try Unity - Scripting API: Input.GetButton