Last active
April 16, 2018 08:01
-
-
Save TakaakiIchijo/a573db662f368c2bd534cb70a8e55fac to your computer and use it in GitHub Desktop.
Unity AudioSource Extention PlayCompleteCallback with async/await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using UnityEngine; | |
public static class AudioSourceExtention | |
{ | |
public static async Task PlayWithCompCallback(this AudioSource audioSource, AudioClip audioClip, float volume = 1f) | |
{ | |
audioSource.Play(audioClip, volume); | |
int audioClipLengthMs = (int)TimeSpan.FromSeconds(audioClip.length).TotalMilliseconds; | |
await Task.Delay(audioClipLengthMs); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment