Audio control utility
Put this in your Packages/manigest.json
file
"com.rsg.promises": "https://github.com/debox-dev/RSG_Promises.git",
"com.debox.audiorig": "https://github.com/debox-dev/Unity_AudioRig.git",
- Unity 2019 or higher.
- RSG Promises
- Create an empty game object
- Add the component AudioPlayer
- Make sure 'isMain' attribute of the AudioPlayer is turned on
- Done!
using DeBox.AudioRig;
[SerializeField] private AudioClip _myClip;
private void Start()
{
AudioPlayer.Main.Play(_myClip);
}
Use the PlayLoop
method
AudioPlayer.Main.PlayLoop(_myClip);
// Plays a clip in a loop, waits 3 seconds, then fades out the clip
private IEnumerator PlayWaitAndFadeOutCoroutine()
{
var audioControl = AudioPlayer.Main.PlayLoop(_myClip);
yield return new WaitForSeconds(3);
audioControl.FadeOut(3);
}
private void StartHumming()
{
this._hummAudioControl = AudioPlayer.Main.PlayLoop(_hummLoopClip);
}
private void Update()
{
// Play at 0.3 volume if the tutorial voice actor is speaking
this._hummAudioControl?.Volume = _isTutorialVoiceSpeaking ? 0.3f : 1f;
}
var control = AudioPlayer.Main.Play(_myClip);
control.Pitch = this._pressedKeyPitch;
var control = AudioPlayer.Main.Play(_myClip);
control.PlayAt(transform.position);
// I am a buzzing be!
var control = AudioPlayer.Main.PlayLoop(_buzzLoop);
control.Follow(transform);
You can stop following at any time with
control.StopFollow();