using UnityEngine;
using System.Collections;

public class bullet : MonoBehaviour {
	public GameObject fier;
	public GameObject fier2;
	public Enemy enemy;
	// Use this for initialization
	void Start () {
		Destroy (gameObject,3);
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate (0.1f, 0, 0);
	}
	void OnCollisionEnter2D(Collision2D col){
		if (col.gameObject.name == "wall") {

			Instantiate(fier,transform.position,transform.rotation);
			Destroy (gameObject);

		}

		if (col.gameObject.tag == "wall2") {
			Instantiate(fier,col.transform.position,transform.rotation);
			Destroy(col.gameObject);
			Destroy (gameObject);

		}
		if (col.gameObject.tag == "ENM") {

			col.gameObject.GetComponent<Enemy>().Health-=1;
			Destroy (gameObject);
			Instantiate(fier,transform.position,transform.rotation);

			if(col.gameObject.GetComponent<Enemy>().Health==0){
			Instantiate(fier2,col.transform.position,transform.rotation);
			Destroy(col.gameObject);
			Destroy (gameObject);
			}
			
		}

		if (col.gameObject.tag == "ENM2") {
			
			col.gameObject.GetComponent<Enemy>().Health-=1;
			Destroy (gameObject);
			Instantiate(fier,transform.position,transform.rotation);
			
			if(col.gameObject.GetComponent<Enemy>().Health==0){
				Instantiate(fier2,col.transform.position,transform.rotation);
				Destroy(col.gameObject);
				Destroy (gameObject);
			}
			
		}
		if (col.gameObject.name == "TANK-EGL") {
			
			Instantiate(fier,col.transform.position,col.transform.rotation);
			col.gameObject.GetComponent<Animator>().enabled=true;

			Destroy (gameObject);
			
		}
	}
}
