using UnityEngine;

public class GoalZone : MonoBehaviour
{
    public string scoringTeam;
    public AudioClip goalSound;

    [Header("Audio Settings")]
    public float goalSoundVolume = 1.5f;

    private AudioSource audioSource;

    void Awake()
    {
        audioSource = gameObject.AddComponent<AudioSource>();
        audioSource.playOnAwake = false;
        audioSource.spatialBlend = 0f; // 2D sound
        audioSource.volume = goalSoundVolume;
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Ball"))
        {
            if (MusicManager.Instance != null)
            {
                MusicManager.Instance.DuckMusic(1.5f);
            }

            if (goalSound != null)
            {
                audioSource.PlayOneShot(goalSound, goalSoundVolume);
            }

            GameManager.Instance.GoalScored(scoringTeam);
        }
    }
}