using UnityEngine;
using System.Collections;

namespace UnityStandardAssets._2D
{
	public class Bala : MonoBehaviour {
		//public float fuerza = 1f;
		float vida = 2;
		// Use this for initialization
		void Start () {
		
		}
		
		// Update is called once per frame
		void Update () {
			vida -= 3 * Time.deltaTime;
			if (vida <= 0) {
				Destroy (gameObject);
			}
			float angulo = transform.rotation.eulerAngles.z;
			float posx = transform.position.x+0.2f*Mathf.Cos(angulo);
			float posy = transform.position.y+0.2f*Mathf.Sin(angulo);
			transform.position = new Vector3(posx,posy,0f);
		}
		void OnTriggerEnter2D(Collider2D other) {
			if (other.CompareTag ("enemigo")) {
				Enemigo e =	other.transform.GetComponent<Enemigo> ();
				if (e != null) {
					e.bajarVida();
					Destroy (gameObject);
				}
			}
		} 
	}
}