move to 3d
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class Hammer : MonoBehaviour
|
||||
@@ -8,6 +9,8 @@ public class Hammer : MonoBehaviour
|
||||
private bool _hasCollided = false;
|
||||
private Rigidbody2D _rigidbody;
|
||||
private Collider2D _collider;
|
||||
private bool _canHit = false;
|
||||
private Coroutine _disableHitCoroutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -61,6 +64,11 @@ public class Hammer : MonoBehaviour
|
||||
|
||||
private void ProcessHit(Collider2D collider, Vector2 impactVelocity, Vector2 contactPoint)
|
||||
{
|
||||
// Only process hits when the hammer is allowed to hit (activated by input)
|
||||
if (!_canHit)
|
||||
return;
|
||||
|
||||
StartCoroutine(ResetCollisionCoroutine());
|
||||
// Check for enemy collision (stun)
|
||||
var enemy = collider.gameObject.GetComponent<Character>();
|
||||
if (enemy != null)
|
||||
@@ -83,6 +91,21 @@ public class Hammer : MonoBehaviour
|
||||
EmitImpactNoise(contactPoint);
|
||||
}
|
||||
|
||||
public void ActivateHit(float duration)
|
||||
{
|
||||
_canHit = true;
|
||||
if (_disableHitCoroutine != null)
|
||||
StopCoroutine(_disableHitCoroutine);
|
||||
_disableHitCoroutine = StartCoroutine(DisableHitAfter(duration));
|
||||
}
|
||||
|
||||
private IEnumerator DisableHitAfter(float duration)
|
||||
{
|
||||
yield return new WaitForSeconds(duration);
|
||||
_canHit = false;
|
||||
_disableHitCoroutine = null;
|
||||
}
|
||||
|
||||
private void HandleEnemyCollision(Character enemy, Vector2 impactVelocity)
|
||||
{
|
||||
// Apply stun to enemy
|
||||
@@ -105,5 +128,11 @@ public class Hammer : MonoBehaviour
|
||||
noiseSystem.Emit(position, _impactNoiseRadius);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ResetCollisionCoroutine()
|
||||
{
|
||||
yield return new WaitForSeconds(0.25f);
|
||||
_hasCollided = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user