x


Audio playing problem

So here's my script (UnityScript):

var yourAudioClip : AudioClip;

function Update(){
if(Input.GetButtonDown)
    audio.PlayOneShot(yourAudioClip);
}

I was hoping this would let me play a sound when I press the down arrow button (the audioclip is on the same game object as this script). Instead, the audio clip is playing indefinetly without me pressing anything. Can anybody help me fix this script so that it will allow me to preform what I want? Sorry, I'm really new, so don't be too hard on me.

more ▼

asked May 12 '12 at 05:45 PM

Orbipefhermiene gravatar image

Orbipefhermiene
-15 1 2

I just edited your question and now I notice the line "if(Input.GetButtonDown)". This is not correct, sorry if I erased the correct one (I'm not sure)

May 12 '12 at 07:17 PM Berenger
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Thanks, this is my script:

var yourAudioClip : AudioClip;

function Update ()

{

if(Input.GetButtonDown)

{

audio.PlayOneShot(yourAudioClip);

}

}

more ▼

answered May 12 '12 at 10:42 PM

Orbipefhermiene gravatar image

Orbipefhermiene
-15 1 2

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

Thanks, this is my script:

var yourAudioClip : AudioClip;

function Update ()

{

if(Input.GetButtonDown)

{

audio.PlayOneShot(yourAudioClip);

}

}

more ▼

answered May 12 '12 at 10:42 PM

Orbipefhermiene gravatar image

Orbipefhermiene
-15 1 2

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

GetButtonDown is called in the frame you press a button, as opposed to GetButtonUp, which is called when the button is released. It is not connected to the arrow keys. As it is now, it doesn't make sense, since you don't specify which button you want to use.

if(Input.GetKeyDown("Down"))
more ▼

answered May 12 '12 at 07:51 PM

Piflik gravatar image

Piflik
5.4k 17 27 45

(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:

x1060

asked: May 12 '12 at 05:45 PM

Seen: 371 times

Last Updated: May 12 '12 at 10:42 PM