UnityGameProjectsCode / InTheDarkGame / Helpers / SoundOnTriggerEnter.cs
SoundOnTriggerEnter.cs
Raw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoundOnTriggerEnter : MonoBehaviour
{
    public AudioSource aSource;
    private bool played;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (played == false && collision.gameObject.CompareTag("Player"))
        {
            aSource.Play();
            played = true;
        }
    }
}