﻿using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour {

	private Animator animator;
	public float damage = 5f;
	public float speed = 1f;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate (Vector3.right * speed * Time.deltaTime);
	}

	void OnTriggerEnter2D (Collider2D collider) {
		GameObject victim = collider.gameObject;
		
		//If not an attacker, then move on.
		if (!victim.GetComponent<Attacker> ()) {
			return;
		} else {
			//decrease health of attacker
			Health victimHealth = victim.GetComponent<Health>();
			victimHealth.TakeDamage(damage);
			Destroy(gameObject);
		}
	}
}
