more changes to make it better
This commit is contained in:
@@ -7,11 +7,14 @@ public class Hammer : MonoBehaviour
|
||||
[SerializeField] private float _impactNoiseRadius = 10f;
|
||||
[SerializeField] private bool _emitNoiseOnImpact = true;
|
||||
|
||||
public event System.Action OnReturnedToHand;
|
||||
|
||||
private float _lifeTimer;
|
||||
private Vector2 _velocity;
|
||||
private bool _facingRight;
|
||||
private Rigidbody2D _rigidbody;
|
||||
private bool _hasCollided = false;
|
||||
private bool _isThrown = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -23,10 +26,12 @@ public class Hammer : MonoBehaviour
|
||||
{
|
||||
_facingRight = facingRight;
|
||||
_velocity = new Vector2(facingRight ? speed : -speed, 0);
|
||||
|
||||
_isThrown = true;
|
||||
|
||||
if (_rigidbody != null)
|
||||
{
|
||||
_rigidbody.linearVelocity = _velocity;
|
||||
_rigidbody.angularVelocity = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +58,7 @@ public class Hammer : MonoBehaviour
|
||||
{
|
||||
HandleEnemyCollision(enemy, collision.relativeVelocity);
|
||||
EmitImpactNoise(collision.GetContact(0).point);
|
||||
Destroy(gameObject);
|
||||
ReturnToHand();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,13 +68,13 @@ public class Hammer : MonoBehaviour
|
||||
{
|
||||
mapElement.Hit();
|
||||
EmitImpactNoise(collision.GetContact(0).point);
|
||||
Destroy(gameObject);
|
||||
ReturnToHand();
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: destroy on any collision
|
||||
// Fallback: return hammer on any collision
|
||||
EmitImpactNoise(collision.GetContact(0).point);
|
||||
Destroy(gameObject);
|
||||
ReturnToHand();
|
||||
}
|
||||
|
||||
private void HandleEnemyCollision(Character enemy, Vector2 impactVelocity)
|
||||
@@ -94,4 +99,13 @@ public class Hammer : MonoBehaviour
|
||||
noiseSystem.Emit(position, _impactNoiseRadius);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReturnToHand()
|
||||
{
|
||||
_isThrown = false;
|
||||
if (OnReturnedToHand != null)
|
||||
{
|
||||
OnReturnedToHand.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user