Playing A Sound in Unity

Here's a simple way to play a sound in Unity. 1. Add something like this to the declaration section of your script. public AudioSource audioSourceExplosion; 2. Add this line of code where you want to play the sound. audioSourceExplosion.Play(); 3. NOTE : What I have called audioSourceExplosion here is the name of the variable and of course must match at step one and two. 4. Add an Audio Source component to the GameObject your script is attached to in the Hierarchy. 5. Attach you sound to the new Audio Component. 5. A public variable should have appeared on your GameObject, drag the Audio Source component onto this variable. Image removed.


In reply to by malcolm


I visit your blog regularly to get new things like this. Thank you

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer