using UnityEngine;
using System.Collections;

public class OneShot3DAudio
{
    // I shouldn't need to do this, but Unity yanked the ability to do 3D sounds with AudioSource.PlayClipAtPoint. :(
	public static void PlayClipAtPoint(AudioClip clip, Vector3 position, float volume, float pitch)
    {
        var gameObject = new GameObject();
        gameObject.transform.position = position;
        var audioSource = gameObject.AddComponent<AudioSource>();
        audioSource.spatialBlend = 1f;
        audioSource.clip = clip;
        audioSource.volume = volume;
        audioSource.pitch = pitch;

        audioSource.Play();
        GameObject.Destroy(gameObject, clip.length / pitch);
	}

    public static void PlayClipAtPoint(AudioClip clip, Vector3 position, float volume)
    {
        PlayClipAtPoint(clip, position, volume, 1f);
    }

    public static void PlayClipAtPoint(AudioClip clip, Vector3 position)
    {
        PlayClipAtPoint(clip, position, 1f, 1f);
    }
}
