using UnityEngine;
using System.Collections;

public class WarningScript : MonoBehaviour {

    public GameObject soldier;
    public int level;

    private bool _activated = false;
    private MilitarWarning _militarWarning;

	// Use this for initialization
	void Start () {
        _militarWarning = soldier.GetComponent<MilitarWarning>();
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnTriggerEnter2D (Collider2D coll)
    {
        if (!_activated && coll.gameObject.tag == "Player")
        {
            _militarWarning.Warn(level);
            _activated = true;
        }
    }

    void OnTriggerExit2D (Collider2D coll)
    {

        if (_activated && coll.gameObject.tag == "Player" && coll.gameObject.transform.position.y < gameObject.transform.position.y)
        {
            
            _militarWarning.Warn(level - 1);
            _activated = false;
        }
    }
}
