Moved fall damage to DamageHandler

This commit is contained in:
go38coz
2026-06-06 14:54:57 +02:00
parent 9d1f04c496
commit 18c0e2a9d6
6 changed files with 593 additions and 162 deletions
+14 -3
View File
@@ -4,11 +4,22 @@ using UnityEngine;
public class DamageHandler : MonoBehaviour
{
public float threshold = 0.05f;
public float multiplier = 5f;
private void OnCollisionEnter(Collision collision)
public float health = 1;
private void OnCollisionEnter2D(Collision2D other)
{
throw new NotImplementedException();
float fallSpeed = GetComponent<Rigidbody2D>().linearVelocityY;
if (fallSpeed > threshold)
{
float fallDamage = (fallSpeed - threshold) * multiplier;
Debug.Log($"Fell with velocity:{fallSpeed}. Fall damage{fallDamage}");
health -= fallDamage;
}
else
{
Debug.Log($"Fell with velocity:{fallSpeed}. No fall damage");
}
}
}