using UnityEngine;
using System.Collections;

public class Building : MonoBehaviour
{

	public string waveTag;

	public float health;

	public GameObject deathParticles;

	// Use this for initialization
	void Start ()
	{
	
	}
	
	// Update is called once per frame
	void Update ()
	{
	



	}

	void OnTriggerEnter2D (Collider2D other)
	{
		if (other.gameObject.tag == waveTag) {
			float currentHealth = health;
			health = health - other.gameObject.GetComponent<Wave> ().height;
			other.gameObject.GetComponent<Wave> ().height -= currentHealth;

			if(health <=0)
			{
				DestroyThis();
			}

		}
	}

	public void DestroyThis ()
	{
        Instantiate(deathParticles, transform.position, Quaternion.Euler(-45, 90, 0));
        GameObject.Find("TimeManager").GetComponent<TimeManager>().StartSlow();
        Destroy (gameObject);
	}

	void OnDestroy()
	{
		
	}

}
