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!