Skip to content

Instantly share code, notes, and snippets.

@TakaakiIchijo
Last active April 16, 2018 08:01
Show Gist options
  • Save TakaakiIchijo/a573db662f368c2bd534cb70a8e55fac to your computer and use it in GitHub Desktop.
Save TakaakiIchijo/a573db662f368c2bd534cb70a8e55fac to your computer and use it in GitHub Desktop.
Unity AudioSource Extention PlayCompleteCallback with async/await
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