using System; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Video; [RequireComponent(typeof(VideoPlayer))] public class AudioPlayControl : MonoBehaviour { public VideoClip startAudio; public VideoClip endAudio; private VideoPlayer player; private void Awake() { player = GetComponent(); player.playOnAwake = false; } public async Task PlayStartVideo() { this.gameObject.SetActive(true); player.clip = startAudio; player.Play(); await Task.Delay((int)(1000 * player.clip.length)); player.Stop(); this.gameObject.SetActive(false); } public async void PlayEndVideo() { player.clip = endAudio; player.Play(); await Task.Delay((int)(1000 * player.clip.length)); player.Stop(); this.gameObject.SetActive(false); } public void StopPlay() { player.Stop(); this.gameObject.SetActive(false); } }