Quantcast
Channel: Questions in topic: "footsteps"
Viewing all articles
Browse latest Browse all 164

Footstep Sound Issue

$
0
0
Hi, Im trying to make footstep audio when i walk in my game. But here is my error: MissingComponentException: There is no 'AudioSource' attached to the "First Person Controller" game object, but a script is trying to access it. You probably need to add a AudioSource to the game object "First Person Controller". Or your script needs to check if the component is attached before using it. FootStepsOn.PlayAudio () (at Assets/FootStepsOn.js:71) FootStepsOn.Update () (at Assets/FootStepsOn.js:11) Here is my code: var walk : AudioClip; var run : AudioClip; var isWalking : boolean = false; var isRunning : boolean = false; function Update() { GetState(); PlayAudio(); } function GetState() { if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ) ) { if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) ) { // Running isWalking = false; isRunning = true; } else { // Walking isWalking = true; isRunning = false; } } else { // Stopped isWalking = false; isRunning = false; } } function PlayAudio() { if ( isWalking ) { if ( GetComponent.().clip != walk ) { GetComponent.().Stop(); GetComponent.().clip = walk; } if ( !GetComponent.().isPlaying ) { GetComponent.().Play(); } } else if ( isRunning ) { if ( GetComponent.().clip != run ) { GetComponent.().Stop(); GetComponent.().clip = run; } if ( !GetComponent.().isPlaying ) { GetComponent.().Play(); } } else { GetComponent.().Stop(); } } AND here is an image that i attached the audio together: ![alt text][1] [1]: /storage/temp/56245-screen-shot-2015-10-14-at-110107-pm.png

Viewing all articles
Browse latest Browse all 164

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>