aboutsummaryrefslogtreecommitdiffstats
path: root/Assets/Scripts/Actors/Enemy.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/Actors/Enemy.cs')
-rw-r--r--Assets/Scripts/Actors/Enemy.cs27
1 files changed, 26 insertions, 1 deletions
diff --git a/Assets/Scripts/Actors/Enemy.cs b/Assets/Scripts/Actors/Enemy.cs
index d7d699e..600fcaf 100644
--- a/Assets/Scripts/Actors/Enemy.cs
+++ b/Assets/Scripts/Actors/Enemy.cs
@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections;
+using UnityEngine.InputSystem;
namespace MontanaJohns.Actors
{
@@ -10,12 +11,18 @@ namespace MontanaJohns.Actors
protected float attackRate = 0.5f;
protected float nextAttackTime = 0f;
- bool playerSeen;
+ private bool playerSeen;
+ private PlayerInput playerInput;
+ private InputAction jump;
protected override void Awake()
{
base.Awake();
player = GameObject.FindGameObjectWithTag("Player");
+ playerInput = player.GetComponent<PlayerInput>();
+
+ jump = playerInput.currentActionMap.FindAction("Jump");
+ jump.started += context => Jump();
}
// Update is called once per frame
@@ -59,6 +66,24 @@ namespace MontanaJohns.Actors
}
}
+ public override void Jump()
+ {
+ if (Physics2D.OverlapCircle(groundCheckPoint1.position, 0.2f, groundLayers) || Physics2D.OverlapCircle(groundCheckPoint2.position, 0.2f, groundLayers))
+ {
+ jumpCount = stats.maxJumps;
+ hangCount = hangTime;
+ }
+ else
+ {
+ hangCount -= Time.deltaTime;
+ }
+ if (jumpCount > 0 && hangCount > 0f)
+ {
+ jumpCount--;
+ _rigidBody.AddForce(Vector2.up * stats.jumpForce);
+ }
+ }
+
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Projectile")