Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / Player / PlayerAttackandBlock.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PlayerAttackandBlock : MonoBehaviour
  5. {
  6. private Rigidbody2D rb;
  7. private BossSlimeLife bossSlimeLife;
  8. private SlimeLife slimelife;
  9. //private Transform attackBoxTransform;
  10. //private BoxCollider2D attackBoxCollider;
  11. private float attackTime = 0.5f;
  12. private float attackCounter = 0.5f;
  13. private float strongAttackHoldTime = 3f;
  14. public bool normalAttack;
  15. public bool strongAttack;
  16. public bool shield;
  17. public int normalPlayerAttack = 10;
  18. public int strongPlayerAttack = 15;
  19. public int defensePlayer = 5;
  20. void Start()
  21. {
  22. rb = GetComponent<Rigidbody2D>();
  23. bossSlimeLife = FindObjectOfType<BossSlimeLife>(); // to access the Player Level file
  24. slimelife = FindObjectOfType<SlimeLife>();
  25. }
  26. void FixedUpdate()
  27. {
  28. if (normalAttack)
  29. {
  30. rb.velocity = Vector2.zero;
  31. normalAttack = false;
  32. }
  33. else if (strongAttack)
  34. {
  35. rb.velocity = Vector2.zero;
  36. strongAttack = false;
  37. }
  38. else if (shield)
  39. {
  40. rb.velocity = Vector2.zero;
  41. }
  42. attackCounter -= Time.fixedDeltaTime;
  43. if (attackCounter <= 0 && shield == false)
  44. {
  45. // Attack
  46. if (Input.GetMouseButton(0))
  47. {
  48. strongAttackHoldTime -= Time.fixedDeltaTime;
  49. }
  50. if (!Input.GetMouseButton(0) && strongAttackHoldTime < 3f)
  51. {
  52. //Basic Attack
  53. if (strongAttackHoldTime > 0)
  54. {
  55. attackCounter = attackTime;
  56. normalAttack = true;
  57. strongAttackHoldTime = 3f;
  58. }
  59. }
  60. //Strong Attack
  61. if (strongAttackHoldTime <= 0)
  62. {
  63. attackCounter = attackTime;
  64. strongAttack = true;
  65. strongAttackHoldTime = 3f;
  66. }
  67. }
  68. //Shield
  69. if (Input.GetKey(KeyCode.Space))
  70. {
  71. shield = true;
  72. }
  73. else
  74. {
  75. shield = false;
  76. }
  77. }
  78. }