using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {

	public float damage = 1f;
	public Transform target;
	public float speed = 12f;

	public bool soulDamage = false;
	
	void Update () {
		if(target == null) {
			Destroy (gameObject);
			return;
		}
		
		
		Vector2 dir = target.position - this.transform.position;
		
		if(dir.magnitude <= 0.2f) {
			DemonLord dl = target.gameObject.GetComponent<DemonLord>();
			if(dl != null) {
				if(soulDamage) {
					dl.lifeSpan -= Mathf.Max(dl.lifeSpan * damage, 20f);
				}
				else {
					dl.lifeSpan -= damage;
				}
			}

			Destroy(gameObject);
		}
		else {
			this.transform.Translate( dir.normalized * speed * Time.deltaTime, Space.World );
		}
		
	}
	
}
