x


turret rotation audio problem

I made a model of a mech type robot. The problem i have is i want to add a sound file when i rotate it. The keys for rotation are a = right and d =left. i have tried following the posts to assign a audio file to this action but having problems. I add an audio source to the object and then a script to it but it keep getting error problems. Can someone help me out with this? I have tried some scripts i found on the forum but they dont work for me. This is a play on push key action

thanks

wayne

more ▼

asked Sep 16 '11 at 08:48 PM

wayne57 gravatar image

wayne57
43 13 30 36

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

1 answer: sort voted first

You must add an AudioSource to the object, assign the sound you want to play to the clip property (at the Inspector) and observe the controls: while they are pressed, play the sound - but you must wait the sound end before play it again, or you will get a horrible noise instead:

function Update(){ // check if a OR d pressed
    if (Input.GetButton("a") || Input.GetButton("d")){
        if (!audio.isPlaying){ // if sound ended...
            audio.Play();      // repeat the sound
        }
    }
}
more ▼

answered Sep 17 '11 at 07:05 AM

aldonaletto gravatar image

aldonaletto
42.5k 16 42 202

(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

By RSS:

Answers

Answers and Comments

Topics:

x29

asked: Sep 16 '11 at 08:48 PM

Seen: 374 times

Last Updated: Sep 17 '11 at 07:12 PM