- Home /
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
Answer by alexnode · Aug 25, 2010 at 11:52 AM
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) 
I keep seeing "Fire1" But I have no idea what it means and what to replace it with. All i knows is keycode.whatever but that doesnt work with getbuttondown. UGHH we all arent as smart as you pros.
Answer by myunity · Aug 25, 2010 at 11:45 AM
It is easy:
 if (Input.GetKeyDown("s"))
 {
     audio.Play();
 }
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.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                