falldamage sound

This commit is contained in:
orsolya-st
2026-06-07 00:57:56 +02:00
parent 549cf62ac6
commit b6762f434a
3 changed files with 149 additions and 10 deletions
+26 -10
View File
@@ -19,6 +19,10 @@ public class DamageHandler : MonoBehaviour
public float maxFallingTime = 2f;
public float fallingAnimTreshold = 0.2f;
//audio stuff
public AudioSource speaker;
public AudioClip fallsound;
private void Awake()
{
@@ -69,16 +73,28 @@ public class DamageHandler : MonoBehaviour
}
private void OnCollisionEnter2D(Collision2D other)
{
// Debug.LogWarning("collide");
//on collision check fall damage
float fallSpeed = lastYVelocity;
if (fallSpeed < -threshold)
{
float fallDamage = (-fallSpeed - threshold) * multiplier;
UpdateHealth(health - fallDamage);
}
}
{
float fallSpeed = lastYVelocity;
// Check if we hit hard enough
if (fallSpeed < -threshold)
{
Debug.Log("Impact detected! Speed: " + fallSpeed);
if (speaker != null && fallsound != null)
{
speaker.PlayOneShot(fallsound);
Debug.Log("Sound played successfully.");
}
else
{
Debug.LogWarning("AudioSource or AudioClip is missing in the Inspector!");
}
float fallDamage = (-fallSpeed - threshold) * multiplier;
UpdateHealth(health - fallDamage);
}
}
private void OnTriggerEnter2D(Collider2D other)
{