using UnityEngine;
using System.Collections;

public class HealthBB : MonoBehaviour {


    public static float healthboss = 500.0f;

    public AudioSource source1;
    public GameObject boom;
    public AudioClip torpedoBoomSFX;
    public GameObject boom2; public GameObject boom3; public GameObject boom4; public GameObject boom5;

    // Use this for initialization
    void Start ()
    {


        boom.SetActive(false);
        boom2.SetActive(false);
        boom3.SetActive(false);
        boom4.SetActive(false);
        boom5.SetActive(false);


    }

    public IEnumerator explosionBB()
    {
        boom.SetActive(true);
        GetComponent<Renderer>().enabled = false;
        source1.clip = torpedoBoomSFX;
        source1.Play();
        yield return new WaitForSeconds(0.5f);
        boom2.SetActive(true);
        source1.clip = torpedoBoomSFX;
        source1.Play();
        yield return new WaitForSeconds(0.5f);
        boom3.SetActive(true);
        source1.clip = torpedoBoomSFX;
        source1.Play();
        yield return new WaitForSeconds(0.5f);
        boom4.SetActive(true);
        source1.clip = torpedoBoomSFX;
        source1.Play();
        yield return new WaitForSeconds(0.5f);
        boom5.SetActive(true);
        source1.clip = torpedoBoomSFX;
        source1.Play();
        yield return new WaitForSeconds(1.0f);
        Destroy(gameObject);

        Score.tpsLvl3 = Mathf.Round(Score.tpsecoulé);
        Score.scoreLvl3 = Score.score + 10 * Score.tpsRestant;

        if (Score.scoreLvl3 > Score.meilleurScoreLvl3)
        {
            Score.meilleurScoreLvl3 = Score.scoreLvl3;
            Score.meilleurTpsLvl3 = Score.tpsLvl3;

            PlayerPrefs.SetFloat("meilleur_score3", Score.meilleurScoreLvl3);
            PlayerPrefs.SetFloat("meilleur_tps3", Score.meilleurTpsLvl3);
        }

        StateMachine.instance.SetState(STATE.SCORE);

    }

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

    public void HealthManage()
    {
        healthboss -= 50;

        if (healthboss == 0)
        {

            StartCoroutine("explosionBB");


        }
    }
}
