x


how do i play a sound if i press a particular key?

Hi

how do i play a sound if i press a particular key

(sorry to ask a stupid question but i find it hard to do the programming)

regards

Bruno

more ▼

asked Aug 25 '10 at 11:27 AM

bruno martelli gravatar image

bruno martelli
135 10 13 24

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

2 answers: sort voted first

Here he is again! I made a custom script with a brunoSound variable !!! ... attach this javascript script to an object, add an audio source and then add a sound file in the inspector next to the variable brunoSound.

var brunoSound : AudioClip;

function Update() {

if (Input.GetButtonDown("Fire1")
{
audio.PlayOneShot(brunoSound);
}
}
@script RequireComponent(AudioSource)
more ▼

answered Aug 25 '10 at 11:52 AM

alexnode gravatar image

alexnode
984 27 32 49

awesome thanks guys!

Aug 27 '10 at 11:10 AM bruno martelli
(comments are locked)
10|3000 characters needed characters left

It is easy:

 if (Input.GetKeyDown("s"))
 {
     audio.Play();
 }
more ▼

answered Aug 25 '10 at 11:45 AM

myunity gravatar image

myunity
167 23 25 33

Hey, how would i use multiple sounds? example if i press D i want my object to play the walk sound, if i press Z i want to play the Jump sound. Also can i create variables that contain my audio which i import into unity please help.

Sep 23 '10 at 03:32 AM MC HALO
(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:

x1025
x980
x166

asked: Aug 25 '10 at 11:27 AM

Seen: 3889 times

Last Updated: Aug 25 '10 at 11:27 AM