using DarkTonic.MasterAudio;
using UnityEngine;


public class ScoreController : MonoBehaviour
{
    #region Singleton

    private static ScoreController _instance;

    public static ScoreController Instance
    {
        get
        {
            if (_instance == null)
                _instance = GameObject.FindObjectOfType<ScoreController>();
            return _instance;
        }
    }

    #endregion

    public int Score;

    public MusicController MusicController = new MusicController();

    public MovetoPlayer _shark;
    public float speedShark1= 0;
    public float speedShark2 = 0;
    public float speedShark3 = 0;

    private void Awake()
    {

            _shark = GameObject.FindGameObjectWithTag("Shark").GetComponent<MovetoPlayer>();

    }
    public void Start()
    {
        MusicController.Initialize();


        
    }

    public void Update()
    {
        
        //solução escrota, cheia de ifs para troca de som conforme o score
        if (Score >= MusicController.ScoreToSecond && Score < MusicController.ScoreToThird)
        {
            CrossFadeToSecond();
            _shark.speed = speedShark1;
        }
        if(Score>=MusicController.ScoreToThird && Score < MusicController.ScoreToFourth)
        {
            CrossFadeToThird();
            _shark.speed = speedShark2;
        }
        if(Score>=MusicController.ScoreToFourth)
        {
            CrossFadeToFourth();
            _shark.speed = speedShark3;
        }
    }

    public void AddScore(int toAdd)
    {
        Score += toAdd;
    }

    [ContextMenu("Change to second")]
    public void CrossFadeToSecond()
    {
        MusicController.ChangeToSecond();
    }

    [ContextMenu("Change to third")]
    public void CrossFadeToThird()
    {
        MusicController.ChangeToThird();
    }

    [ContextMenu("Change to fourth")]
    public void CrossFadeToFourth()
    {
        MusicController.ChangeToFourth();
    }
}