using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

public class AudioController : MonoBehaviour
{
    // Singleton
    public static AudioController Instance = null;

    public AudioSource music1;
    public AudioSource music2;

    private bool playing1;
    
    public AudioSource sounds;
    
    // Initialize the singleton instance.
    private void Awake()
    {
        // Set instance if null
        if (Instance == null)
        {
            Instance = this;
        }
        // If exist a instance, destroy
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        //Set AudioManager to DontDestroyOnLoad
        DontDestroyOnLoad(gameObject);
    }

    public void PlayMusic(AudioClip clip)
    {
        if (playing1)
        {
            music1.DOFade(0, 1);
            music2.clip = clip;
            music2.Play();
            music2.DOFade(1, 1);
        }
        else
        {
            music2.DOFade(0, 1);
            music1.clip = clip;
            music1.Play();
            music1.DOFade(1, 1);
        }

        playing1 = !playing1;
    }

    public void PlaySound(AudioClip clip)
    {
        sounds.PlayOneShot(clip);
    }

    public void PlayContinousSound(AudioClip clip)
    {
        sounds.clip = clip;
        sounds.Play();
    }

    public void StopContinousSound()
    {
        sounds.Stop();
    }
}
