using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class musicinGame : MonoBehaviour
{

    public AudioSource aso;
    public AudioClip music;

    public float mfadeDuration = 1f;
    // Start is called before the first frame update
    void Start()
    {
        PlaySound();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private IEnumerator mFadeOutMusic()
    {
        float startVolume = aso.volume; // Mevcut ses seviyesi
        float elapsedTime = 0f;

        while (elapsedTime < mfadeDuration)
        {
            elapsedTime += Time.deltaTime;
            aso.volume = Mathf.Lerp(startVolume, 0f, elapsedTime / mfadeDuration); // Volume'yi azalt
            yield return null;
        }

        aso.volume = 0f; // Volume'yi tamamen 0 yap
        aso.Stop(); // Sesi durdur (isteğe bağlı)
    }


    public void PlaySound()
    {
        if (music != null)
        {
            aso.clip = music;
            aso.Play();
        }
    }
}
