using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioSourcePrefab : MonoBehaviour
{
    private AudioSource source;

    private float timeToDeath = Single.NaN;
    void Awake()
    {
        source = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        if (!float.IsNaN(timeToDeath))
        {
            timeToDeath -= Time.deltaTime;

            if (timeToDeath <= 0)
            {
                Destroy(gameObject);
            }
        }
    }

    public void setClip(AudioClip clip, float delay)
    {
        source.clip = clip;
        source.PlayDelayed(delay);
        timeToDeath = delay + clip.length;
    }
}
