using UnityEngine;
using System.Collections;

public class Attack : MonoBehaviour {
	MyManager manager;
	float _baseAttackDamage = 10f;
	float _attackDamage = 0f;
	public float coolDown = 1f;
	float coolDownMax = 0.5f;
	AudioSource myAudio;


	void Awake()
	{
		manager = GameObject.Find("MyManager").GetComponent<MyManager>();
		//myAudio = gameObject.GetComponent<AudioSource>();
		myAudio = gameObject.AddComponent<AudioSource>();
		myAudio.clip = Resources.Load("PlayerHit") as AudioClip;
	}

	void Update()
	{
		_attackDamage = _baseAttackDamage + (manager.player.skills.GetSkill("Strength") * 2);
		//Debug.Log(_attackDamage);

		if(coolDown > 0)
		{
			coolDown -= Time.deltaTime;
		}
	}

	//public void DoAttack()
	//{
		//Debug.Log("I attacked yo!");
	//}

	void OnCollisionStay2D(Collision2D col)
	{
		if(col.gameObject.tag == "Enemy")
		{
			if(coolDown <= 0)
			{
				if(Input.GetButton("Fire1"))
				{
					coolDown = coolDownMax;
					Enemy myEnemy = col.gameObject.GetComponent<Enemy>();
					myEnemy.Hit((int)_attackDamage);
					myAudio.Play();
				}
			}
		}
	}

}
