Playing Audio

Play a Sound from Script

1

Open up your Script

Find where you want to play a sound from.

2

Play a Sound

Keep in mind, to play a sound it must be assign in the Soundify script. Look in Setup for more information.

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:

    Soundify.PlaySound("Background Music");
  • By reference:

    public Sound sound;
    
    Soundify.PlaySound(sound);

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

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.
	}
}

Play a Sound automatically using the Audio Player

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

1

Add the Audio Player to any Game Object

2

Add a new entry

Add a new entry by pressing the Add (+) button.

3

Change the Sound to the Sound you want to play

The sound must be assigned in the Soundify script. See Setup for more information.

4

Add the destination where you want to play the Sound from

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

5

Play the Sound

Press the Subscribe button to automatically generate the code that plays the sound in your attached method.

Last updated