using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAttack : MonoBehaviour {
		public bool attacking = false;
		private float attackTimer = 0;
		public float attackCd = 0.3f;
		public string pName; 
		public Collider attackTrigger;
		private Animator anim;
	// Use this for initialization
		void Awake (){
				anim = gameObject.GetComponent<Animator> ();
				attackTrigger.enabled = false;
		}

	void Start () {
				pName = gameObject.GetComponent<MailboyMove> ().pName;
					
	}
	
	// Update is called once per frame
	void Update () {
		if (GameManager.GM.GetState () == GS.Ready || GameManager.GM.GetState () == GS.Playing) {
			if (Input.GetButtonDown (pName + " A") && !attacking) {
				attacking = true;
				attackTimer = attackCd;
				attackTrigger.enabled = true;
			}
			if (attacking) {
				if (attackTimer > 0)
					attackTimer -= Time.deltaTime;
				else {
					attacking = false;
					attackTrigger.enabled = false;
				}
			}
			anim.SetBool ("attacking", attacking);
		}
	}
}
