Check if audioclip is playing

I use this code:

using UnityEngine;
using System.Collections;

/// <summary>
/// Creating instance of sounds from code with no effort
/// </summary>
public class SoundEffectsHelper : MonoBehaviour
{
	
	/// <summary>
	/// Singleton
	/// </summary>
	public static SoundEffectsHelper Instance;
	
	public AudioClip explosionSound;
	public AudioClip playerShotSound;
	public AudioClip enemyShotSound;
	
	void Awake()
	{
		// Register the singleton
		if (Instance != null)
		{
			Debug.LogError("Multiple instances of SoundEffectsHelper!");
		}
		Instance = this;
	}
	
	public void MakeExplosionSound()
	{
		MakeSound(explosionSound);
	}
	
	public void MakePlayerShotSound()
	{
		MakeSound(playerShotSound);
	}
	
	public void MakeEnemyShotSound()
	{
		MakeSound(enemyShotSound);
	}
	
	/// <summary>
	/// Play a given sound
	/// </summary>
	/// <param name="originalClip"></param>
	private void MakeSound(AudioClip originalClip)
	{
		// As it is not 3D audio clip, position doesn't matter.
		AudioSource.PlayClipAtPoint(originalClip, transform.position);
	}
}

From Making some noises on music — Pixelnest Studio. It works okay. But I want to not allow the same type of AudioClip to be used more than once at the same time. I tried adding if (!audio.isPlaying) play_it and rewriting PlayClipAtPoint to Play, but it didn’t work, because I guess audio is the same for all of these audioclips. What can I do?

AudioSource.PlayClipAtPoint is a convenience function for playing “fire and forget sounds”. What you want is to have an AudioSource component on your Game object. Here’s how:

Just before your class, add [RequireComponent(typeof(AudioSource))]. This will tell Unity to automatically add an AudioSource component whenever your component is added, which will be accessible through the audio property.

Next, change MakeSound to look like this:

private void MakeSound(AudioClip originalClip)
{
    audio.clip = originalClip;
    audio.Play();
}

This will play your desired clip at wherever your component is. If you need to check the playing status, simply check audio.isPlaying.