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

public class npcAttack : MonoBehaviour {

    public int whichPlayer = 1;
    public Transform prefab;
    public float attackOffsetX = 3.0f;
    public float attackOffsetY = 1.4f;
    public Animator animator;
    public float attackCooldown = 5.0f;
    private bool canHit = true;
    AudioSource sndPlayer;
    // Use this for initialization
    void Start()
    {
        sndPlayer = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire2_P" + whichPlayer) && canHit == true)
        {
            playSound();
            canHit = false;
            Invoke("attackTimer", attackCooldown);
            if (GetComponent<SpriteRenderer>().flipX == true)
            {
                attackOffsetX = 2.0f;
            }
            else
            {
                attackOffsetX = -2.0f;
            }
            animator.SetBool("isAttacking", true);
        }
        else
        {
            animator.SetBool("isAttacking", false);
        }
        if (Input.GetButtonDown("Fire1_P" + whichPlayer) && canHit == true)
        {
            canHit = false;
            Invoke("attackTimer", attackCooldown);
        }
    }

    void attackTimer()
    {
        canHit = true;
    }

    public void playSound()
    {
        sndPlayer.Play();
    }
}
