Play Sound on Destroy

So I have looked around the Internets and I haven’t been able to find a decent explaination for my question. Basically I want a short clip to play after my character “picks up” a coin (more like destroys it). I’ve tried several times using different techniques so I just wanted to ask myself to see if anyone can tell me how to make this work. Here’s the code, and if you need any clarification I’d be happy to help.

using UnityEngine;
using System.Collections;

public class PowerUpScript : MonoBehaviour {

	HUDScript hud;

	void OnTriggerEnter2D(Collider2D other)
	{

		if(other.tag == "Player")
		{
			hud = GameObject.Find ("Main Camera").GetComponent<HUDScript>();
			hud.IncreaseScore(10);
			Destroy (this.gameObject);

		}
	}

}

Hi, I am a new developer too so I apologise in advance if my solution does not work :slight_smile:

I think this may work

using UnityEngine;
using System.Collections;
 [RequireComponent] (typeof (AudioSource))]
public class PowerUpScript : MonoBehaviour {
 
    HUDScript hud;
 
    void OnTriggerEnter2D(Collider2D other)
    {
 
       if(other.tag == "Player")
       {
         hud = GameObject.Find ("Main Camera").GetComponent<HUDScript>();
         hud.IncreaseScore(10);
         Destroy (this.gameObject);
         audio.Play();

 
       }
    }
 
}

Then go back into Unity and then click on the object with the script(the coin i think) and add Component>Audio>Audio Source from the top of Unity, untick “Play on awake” Drag the audio clip into the “Audio Clip” on the right. Then test it?