.Play()
.Pause()
.Stop()
[SerializeField] AudioSource audio; if (PlayerGrabbedCoin) audio.Play(); if (DoSomethingElse) audio.Stop();
Download royalty-free music by Kevin MacLeod from here.
Play it on a loop in a scene.
Time to add sound effects to your game! Either:
a) Download from freesound (you'll need an account) b) Record with your PC mic by using Audacity c) Create new sounds by using bfxr
Then, add sounds to your game that can be triggered to play a) when a GameObject gets created b) Calling audioSource.Play() with code
audioSource.Play()
There are many ways to fade in/out audio. Here, we present an example that needs very minimal code.
using UnityEngine.Audio; ... [SerializeField] AudioMixerSnapshot VolumeOn;
VolumeOn.TransitionTo(3); // fade takes 3 seconds
Here's what the audio mixer asset looks like when expanded.
Here, the Master audio mixer group is dragged to Audio Source, and the VolumeOn snapshot to SceneManager.