using UnityEngine;
using System.Collections;

public class MilitarWarning : MonoBehaviour {

    public float timeToShoot;

    private bool _waitingToShoot = false;
    private float _timeWaiting = 0f;
    private GameObject _player = null;
    private AudioSource _audioSource;

	// Use this for initialization
	void Start () {
        _player = GameObject.Find("Player");
        _audioSource = GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {
	
        if (_waitingToShoot)
        {
            _timeWaiting += Time.deltaTime;

            if (_timeWaiting >= timeToShoot)
            {
                _waitingToShoot = false;
                _timeWaiting = 0;
                GetComponent<Animator>().SetInteger("Special", 5);

                _audioSource.Play();

                _player.GetComponent<PlayerScript>().Die();
            }
        }

	}

    public void Warn(int level)
    {
        if (level == 1)
        {
            GetComponent<Animator>().SetInteger("Special", 3);
            GetComponentsInChildren<AudioSource>()[1].Play();
            GetComponent<BasicScript>().ReceiveAction(2, MilitarBasic.Intentions.NONE, this.gameObject);
            _waitingToShoot = false;
        }
        else if (level == 0)
        {
            GetComponent<Animator>().SetInteger("Special", 2);
            _waitingToShoot = false;
        }
        else if (level == 2)
        {
            GetComponent<Animator>().SetInteger("Special", 4);
            GetComponentsInChildren<AudioSource>()[2].Play();
            GetComponent<BasicScript>().ReceiveAction(3, MilitarBasic.Intentions.NONE, this.gameObject);
            _timeWaiting = 0;
            _waitingToShoot = true;
        }
    }
}
