Problem with playing sound on Trigger-Enter

I am trying to play a short sound when the player enters a trigger/walks into a coin-object.
I imported the sound I want, and tried different things, but nothing worked so far.

I tried making a javascript

var soundFile:AudioClip;
 
function OnTriggerEnter(trigger:Collider) {
     if(trigger.collider.tag=="Player") {
        audio.clip = soundFile;
        audio.Play();
     }
}

added the sound in the inspector, though it doesn’t play at all.

I tried adding it to my C#-script I allready have for the coin and created an audio-source on the object, but it doesn’t play either:

[RequireComponent(typeof(AudioSource))]
public class Coin : MonoBehaviour {

	private AudioClip gong;

	void OnTriggerEnter(Collider c) 
	{
	
		if (c.gameObject.tag == "Player") 
		{
			audio.PlayOneShot(gong, 1.0f);
			//audio.Play();
			Destroy (gameObject);
		}

	}
}

I tried both audio.PlayOneShot, as well as audio.Play (not sure how many others there are), no sound plays at all. Is there something I need to check in the Audio-Source? I unchecked “Play On Awake” since I want the sound only when entering the Trigger. With Play on Awake, it played when loading the Scene at the beginning at least.

For your C# script:

 [RequireComponent(typeof(AudioSource))]
 public class Coin : MonoBehaviour {
 
     private AudioSource Source;
     public AudioClip gong;

void Start()
{
Source = GetComponent<AudioSource>();
}
 
     void OnTriggerEnter(Collider c) 
     {
     
         if (c.gameObject.tag == "Player") 
         {
             //audio.PlayOneShot(gong, 1.0f);
             //audio.Play();

             Source.Clip = gong;
             Source.Play();

             Destroy (gameObject);
         }
 
     }
 }

Are You calling Destroy on object with AudioSource that’s playing the sound?

audio.PlayOneShot(gong, 1.0f); //Here audio starts being player
Destroy(gameObject); //And here ends, possibly even in the same frame

If You wan’t to destroy this gameobject and not need settings audio effects in inspector try

AudioClip clip;

void OnTriggerEnter(Collider c)
{
 AudioSource.PlayClipAtPoint(clip, gameObject.position);
 Destroy(gameObject);
}