public void playerSpriteUpdate(pDir playerD)
 {
     if (playerD == pDir.Up)
     {
         anim.SetInteger("direction", 0);
     }
     else if (playerD == pDir.Down)
     {
         anim.SetInteger("direction", 2);
     }
     else if (playerD == pDir.Left)
     {
         anim.SetInteger("direction", 3);
     }
     else
     {
         anim.SetInteger("direction", 1);
     }
 }
 public void playerOrientation()
 {
     //First, check if a button is down or not.
     if (!moving)
     {
         if (Input.GetKey(KeyCode.W))
         {
             moving = true;
             anim.SetBool("moving", true);
             timeUp += Time.deltaTime;
         }
         if (Input.GetKey(KeyCode.S))
         {
             moving = true;
             anim.SetBool("moving", true);
             timeDown += Time.deltaTime;
         }
         if (Input.GetKey(KeyCode.A))
         {
             moving = true;
             anim.SetBool("moving", true);
             timeLeft += Time.deltaTime;
         }
         if (Input.GetKey(KeyCode.D))
         {
             moving = true;
             anim.SetBool("moving", true);
             timeRight += Time.deltaTime;
         }
     }
     else
     {
         if (Input.GetKey(KeyCode.W))
         {
             timeUp += Time.deltaTime;
         }
         else
         {
             timeUp = 0;
         }
         if (Input.GetKey(KeyCode.S))
         {
             timeDown += Time.deltaTime;
         }
         else
         {
             timeDown = 0;
         }
         if (Input.GetKey(KeyCode.A))
         {
             timeLeft += Time.deltaTime;
         }
         else
         {
             timeLeft = 0;
         }
         if (Input.GetKey(KeyCode.D))
         {
             timeRight += Time.deltaTime;
         }
         else
         {
             timeRight = 0;
         }
         if (timeUp > timeDown && timeUp > timeLeft && timeUp > timeRight)
         {
             playerDirection = pDir.Up;
         }
         if (timeDown > timeUp && timeDown > timeLeft && timeDown > timeRight)
         {
             playerDirection = pDir.Down;
         }
         if (timeRight > timeDown && timeRight > timeLeft && timeRight > timeUp)
         {
             playerDirection = pDir.Right;
         }
         if (timeLeft > timeDown && timeLeft > timeUp && timeLeft > timeRight)
         {
             playerDirection = pDir.Left;
         }
         if (!(Input.GetKey(KeyCode.W)) && !(Input.GetKey(KeyCode.S)) && !(Input.GetKey(KeyCode.A)) && !(Input.GetKey(KeyCode.D)))
         {
             moving = false;
             anim.SetBool("moving", false);
         }
     }
     //Debug.Log(playerDirection);
     //OnKeyUp, set that respective value to 0.
     //Then last, set direction to whatever is the largest (or leave it if all buttons are untouched and thus the player is not moving).
 }
 public void attack(pDir currentDirection)
 {
     if (!attacking)
     {
         if (attackTimer <= 0 && Input.GetKeyDown(KeyCode.Space))
         {
             hitbox.velocity = Vector2.zero;
             if (currentDirection == pDir.Up)
             {
                 BoxCollider2D tempHitbox  = atkHitboxes[0].GetComponent <BoxCollider2D>();
                 int           targetCount = tempHitbox.Cast(Vector2.zero, capTargets);
                 for (int i = 0; i < targetCount && i < capTargets.Length; i++)
                 {
                     RaycastHit2D hit   = capTargets[i];
                     Enemy        tempE = hit.transform.GetComponent <Enemy>();
                     tempE.hp -= (Controller.Instance.baseATK + Controller.Instance.wepATK);
                     tempE.rb.AddForce(Vector2.up * Controller.Instance.knockbackForce);
                     Debug.Log("Swung up, hit something!");
                     //Play the animation.
                 }
                 if (targetCount == 0)
                 {
                     Debug.Log("Swung up, no targets!");
                 }
             }
             if (currentDirection == pDir.Down)
             {
                 BoxCollider2D tempHitbox  = atkHitboxes[1].GetComponent <BoxCollider2D>();
                 int           targetCount = tempHitbox.Cast(Vector2.zero, capTargets);
                 for (int i = 0; i < targetCount && i < capTargets.Length; i++)
                 {
                     RaycastHit2D hit   = capTargets[i];
                     Enemy        tempE = hit.transform.GetComponent <Enemy>();
                     tempE.hp -= (Controller.Instance.baseATK + Controller.Instance.wepATK);
                     tempE.rb.AddForce(Vector2.down * Controller.Instance.knockbackForce);
                     Debug.Log("Swung down, hit something!");
                     //Play the animation.
                 }
                 if (targetCount == 0)
                 {
                     Debug.Log("Swung down, no targets!");
                 }
             }
             if (currentDirection == pDir.Left)
             {
                 BoxCollider2D tempHitbox  = atkHitboxes[2].GetComponent <BoxCollider2D>();
                 int           targetCount = tempHitbox.Cast(Vector2.zero, capTargets);
                 for (int i = 0; i < targetCount && i < capTargets.Length; i++)
                 {
                     RaycastHit2D hit   = capTargets[i];
                     Enemy        tempE = hit.transform.GetComponent <Enemy>();
                     tempE.hp -= (Controller.Instance.baseATK + Controller.Instance.wepATK);
                     tempE.rb.AddForce(Vector2.left * Controller.Instance.knockbackForce);
                     Debug.Log("Swung left, hit something!");
                     //Play the animation.
                 }
                 if (targetCount == 0)
                 {
                     Debug.Log("Swung left, no targets!");
                 }
             }
             if (currentDirection == pDir.Right)
             {
                 BoxCollider2D tempHitbox  = atkHitboxes[3].GetComponent <BoxCollider2D>();
                 int           targetCount = tempHitbox.Cast(Vector2.zero, capTargets);
                 for (int i = 0; i < targetCount && i < capTargets.Length; i++)
                 {
                     RaycastHit2D hit   = capTargets[i];
                     Enemy        tempE = hit.transform.GetComponent <Enemy>();
                     tempE.hp -= (Controller.Instance.baseATK + Controller.Instance.wepATK);
                     tempE.rb.AddForce(Vector2.right * Controller.Instance.knockbackForce);
                     Debug.Log("Swung right, hit something!");
                     //Play the animation.
                 }
                 if (targetCount == 0)
                 {
                     Debug.Log("Swung right, no targets!");
                 }
             }
             attackTimer = attackCD;
             attacking   = true;
             anim.SetBool("attacking", true);
         }
     }
     else if (attackTimer < 0 && attacking)
     {
         attacking = false;
         anim.SetBool("attacking", false);
     }
     attackTimer -= Time.deltaTime;
 }