SteamVR: Adding Sound to Vive Controller Input

Rushil Reddy

Building on our previous project, we are now going to add a sound whenever we fire a gun. Import the audio sound (“Free Weapons Solider Sounds Pack from the Unity Asset Store).Make sure your gun prefab is selected in your scene(fire.mp3) and go to your inspector panel. Go to Add Component> AudioSource. Drag the clip we just imported into the Audio Sources AudioClip value.

Now open up the controllerManager script and add these lines in.

public AudioClip shotSound;

AudioSource audio;

void Start() {

     audio = GetComponent ();

}

void Update() {

//Previous code here

     audio.PlayOneShot (shotSound, 0.7f);

}

That’s it! Your gun should now play the sound whenever you pull trigger and fire a bullet.