Advertisement
apieceoffruit

Play Audioclip

Dec 13th, 2023 (edited)
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using JS;
  2. using UnityEngine;
  3.  
  4. // get Audio Converter Here: https://pastebin.com/ND1misd2
  5. // Don't forget to Download the NAudio-Unity.dll
  6. // Should be able to find it on github
  7.  
  8. public class PlayAudioClipFromPath : MonoBehaviour
  9. {
  10.     [SerializeField]
  11.     AudioSource _source;
  12.  
  13.     [SerializeField]
  14.     string _filePath;
  15.    
  16.     [ContextMenu("Load and Play")]
  17.     public async void LoadAndPlay()
  18.     {
  19.         var clip = await AudioConverter.LoadAudioFile(_filePath);
  20.         _source.clip = clip;
  21.         _source.Play();
  22.     }
  23.  
  24.  
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement