Before updating to Windows 10 you may need to return your Pro license. More information here

FPS Audio Walking Script

Hi, does any one know where I'v gone wrong here. Iv got is so when I press W, A or S my audio plays and it doesn't matter if I press two at the same time it still plays the audio. The only problem I have now is the audio Loops too fast is there any way of stopping this?

var sounds : AudioClip; var keyDown = false;

function update() {

if((Input.GetKey("w"))||(Input.GetKey("a"))||(Input.GetKey("d"))) { audio.clip = sounds; audio.Play(); audio.loop = true; keyDown = true;
}else{ keyDown = false; audio.clip = sounds; audio.loop = false; }



more ▼

asked Dec 04, 2010 at 02:39 PM

avatar image

13 6 4 10

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

Check out the FPS tutorial for a walk through... If anyone else can go through your script and actually see what to do, then I'd wait for that. But until then, see what you can see on your own...

Check the FPSPlayer script, they use an array of walking sounds to vary it up.

function PlayStepSounds () { var controller : CharacterController = GetComponent(CharacterController);

 while (true) {
     if (controller.isGrounded && controller.velocity.magnitude > 0.3) {
         audio.clip = walkSounds[Random.Range(0, walkSounds.length)];
         yield WaitForSeconds(audioStepLength);
     } else {


And it is called during the awake function... See if that helps.

Link to the tutorial: http://unity3d.com/support/resources/tutorials/fpstutorial.html

All the best!

more ▼

answered Dec 05, 2010 at 02:58 AM

avatar image

Justin Warner
6.8k 45 55 108

(comments are locked)
10|3000 characters needed characters left

i would think if you put in a scheduled timer, like the yield WaitForSeconds(audioStepLength); that would be what you are looking for and just mess around with the time till you got it where you want it.

I'm new to Unity and haven't got into coding anything yet, but i'm sure you can set a timer to wait to begin the loop again.

more ▼

answered May 08, 2011 at 07:32 AM

avatar image

1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Dec 04, 2010 at 02:39 PM

Seen: 4841 times

Last Updated: Dec 04, 2010 at 02:39 PM