# Playing Audio

## Play a Sound from Script

{% stepper %}
{% step %}

### Open up your Script

Find where you want to play a sound from.
{% endstep %}

{% step %}

### Play a Sound

Keep in mind, to play a sound it **must** be assign in the `Soundify` script. [Look in Setup for more information.](https://saitama-studio.gitbook.io/soundify/basics/editor)

To play a sound, we can either call a sound by its reference as a property in the inspector or by its name directly.

* By name:

  ```csharp
  Soundify.PlaySound("Background Music");
  ```
* By reference:

  ```csharp
  public Sound sound;

  Soundify.PlaySound(sound);
  ```

Here is an example of a script that plays a sound whenever the game starts:

```csharp
using UnityEngine;
using ASoundify; // Import the namespace.

public class AudioTest : MonoBehaviour {
	public Sound sound; // Property in the inspector.
	
	private void Start() {
		Soundify.PlaySound(sound); // Play the sound on game startup.
	}
}
```

{% endstep %}
{% endstepper %}

## Play a Sound automatically using the Audio Player

The `Audio Player` script lets you add the reference to play a sound automatically without coding.

{% stepper %}
{% step %}

### Add the Audio Player to any Game Object

<figure><img src="https://3620304989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDZSZoiaaNHy3U3yJRrvP%2Fuploads%2FCSjtXYqSaKxu7NcauOGv%2Fimage.png?alt=media&#x26;token=0cacbaab-1169-408d-94c2-fe3ac917ded8" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Add a new entry

<figure><img src="https://3620304989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDZSZoiaaNHy3U3yJRrvP%2Fuploads%2FkBwACiuYqbUJuEHWOugc%2Fimage.png?alt=media&#x26;token=cb628743-fe24-4f02-a954-323b291dd1b4" alt=""><figcaption></figcaption></figure>

Add a new entry by pressing the Add **(+)** button.
{% endstep %}

{% step %}

### Change the Sound to the Sound you want to play

The sound **must** be assigned in the `Soundify` script. [See Setup for more information.](https://saitama-studio.gitbook.io/soundify/basics/editor)
{% endstep %}

{% step %}

### Add the destination where you want to play the Sound from

<figure><img src="https://3620304989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDZSZoiaaNHy3U3yJRrvP%2Fuploads%2FOTQQ6omV8rftjMQzQfbe%2Fimage.png?alt=media&#x26;token=b97174d2-5971-49e9-bf17-096bfb1a5757" alt=""><figcaption></figcaption></figure>

Just like a normal Unity Event, add the method where you want to play the sound from.
{% endstep %}

{% step %}

### Play the Sound

Press the **Subscribe** button to automatically generate the code that plays the sound in your attached method.
{% endstep %}
{% endstepper %}
