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.

One thought on “Playing A Sound in Unity

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s