You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This asset provides an easy solution for **playing audio clips, sound effects and music** without needing to worry about managing Audio Sources.
2
+
This asset provides an easy solution for **playing audio clips, sound effects and music** without needing to worry about managing Audio Sources. I've designed it to be simply plug-and-play with no setup required.
3
+
4
+
Features:
5
+
- Play an audio clip at any time and control playback without worrying about Audio Sources.
6
+
- Play a music track, automatically fading in and out between tracks.
7
+
- Create - and play - sound effect assets, assisting in setting up specific types of sounds (e.g. footsteps, gunshots, etc.)
8
+
- Play audio clips, music and sound effects easily from the Unity Resources folder.
9
+
- Helpful audio-related functions.
3
10
4
11
## Setup
5
12
Simply import the package into your project and you're good to go. No additional setup is required.
@@ -8,3 +15,46 @@ Simply import the package into your project and you're good to go. No additional
- <i>Or</i> add the following line to <i>Packages/manifest.json</i>:</br>``"com.davidfdev.audio": "https://github.com/DavidF-Dev/Unity-Audio.git"``
18
+
19
+
## Usage
20
+
No setup is required. To access the scripts, include the ``DavidFDev.Audio`` namespace at the top of your file. The core functionality of the asset is contained in the ``Audio`` static class, which exposes methods for playing audio clips, sound effects & music.
21
+
-``Play(AudioClip, Position [optional], AudioMixerGroup [optional])``: play the provided audio clip.
22
+
-``Play(Path, Position [optional], AudioMixerGroup[optional])``: play an audio clip loaded from the Resources folder.
23
+
-``PlaySfx(SoundEffect, Position [optional])``: play the provided sound effect.
24
+
-``PlaySfx(Path, Position [optional])``: play a sound effect loaded from the Resources folder.
25
+
-``PlayMusic(AudioClip, FadeIn, FadeOut)``: play the provided music track.
26
+
-``PlayMusic(Path, FadeIn, FadeOut)``: play a music track loaded from the Resources folder.
27
+
28
+
</br>Calling ``Play()`` or ``PlaySfx()`` will return an instance of Playback which allows control of the Audio Source indirectly.
29
+
E.g.
30
+
```cs
31
+
Playbackplayback=Audio.PlaySfx(sfx);
32
+
playback.Pause();
33
+
playback.Volume=0.4f;
34
+
playback.Loop=true;
35
+
```
36
+
37
+
</br>Sound effects are scriptable objects that can be added to your Assets. They are used for setting up specific types of sounds. An instance can be played by calling the ``Play()`` method or by passing it in to ``Audio.PlaySfx()``.
38
+
39
+
### Examples
40
+
```cs
41
+
Audio.Play("Audio/death_scream", enemy.position);
42
+
```
43
+
This call will load the `death_scream` Audio Clip from the Resources folder and play it at the enemy's position.
Debug.Log($"Current music track: {Audio.CurrentMusic.name}");
48
+
```
49
+
Playing a music track will crossfade the new track with the old track, if one was already playing. The currently playing music track can be queried through ``Audio.CurrentMusic``.
An Audio Mixer Group can be provided to control where the audio signal is routed. Also, a sound can be stopped prematurely by calling ``ForceFinish()`` on the Playback instance. Note that - unlike with Audio Sources - Playback instances cannot be replayed once the audio has finished playing.
56
+
57
+
## Contact
58
+
If you have any questions or would like to get in contact, shoot me an email at contact@davidfdev.com. Alternatively, you can send me a direct message on Twitter at [@DavidF_Dev](https://twitter.com/DavidF_Dev).</br></br>
59
+
Consider showing support by [buying me a bowl of spaghetti](https://www.buymeacoffee.com/davidfdev) 🍝</br>
60
+
View my other Unity tools on my [website](https://www.davidfdev.com/tools) 🔨
0 commit comments