Unity VR Random audio

Posted May 21, 2022

Unity is new software for me.

I am sharing what I find helpful, in this case setting up Random audio using some scripts from learn.unity.com – I am working on macOS with an Oculus Quest 2.

I hope your find it helpful.

How I added random sounds

Note : For this project I am using v2020.3.2f1

A few notes

If you have 30 hours, take a look at the Unity: Create with VR Course – highly recommended!

I had to figure out how to add the random audio for a project challenge, so I thought I would share how I did it.

You can add random audio to any game object

2. Start by getting the scripts from the Create with VR Starter Project … we will need the two scripts ‘Play Sounds From List’ and ‘On Timed Intervals’. The files are in the _Course LIbrary folder

Unity - adding 'On Timed Intervals' script
unity - add 'PlaySounds from list' script

2. Next, select a game object and add some audio, make sure to set ‘Spatial Blend’ to 1 (3D).

unity - add audio with spacial blend

3. Now we will ‘Add Component’ – Play Sounds From List

unity add component 'Play Sounds From List'

4. Add the audio clips you want to use for your random audio.

Add audio clips for random sounds

5. Add Component – On Timed Intervals

unity add component on timed intervals

6. Set the Min interval (minimum amount of time between audio clips) and Max interval (maximum amount of time between audio clips).

unity - set 'On Timed Intervals' script, min and max interval

7. Where it shows (None (Object) …. drag in your game object, in my case it is called ‘Tree_Med’ from the Hierarchy, and then we will be able to set the function, in my case I set it to ‘PlaySoundsFromList.RandomClip’.

Unity - 'On Timed Intervals' filled in

You should be able to save, build and run and test your random audio in VR.

Let me know if this tutorial helped.

Helpful videos and other links

Excellent video from Unity on all of the steps of setting up your first VR Scene  – https://learn.unity.com/course/create-with-vr?uv=2020.3

Rob Shocks XR Guide – helped me a lot – https://www.youtube.com/watch?v=JyxbA2bm7os

Sideloading Apps on Oculus Quest – https://learn.adafruit.com/sideloading-on-oculus-quest/enable-developer-mode