From b6762f434aa449a403acee88d4197855f26cbb01 Mon Sep 17 00:00:00 2001 From: orsolya-st Date: Sun, 7 Jun 2026 00:57:56 +0200 Subject: [PATCH] falldamage sound --- Game/Assets/Prefabs/PlayerDroplet.prefab | 121 +++++++++++++++++++++++ Game/Assets/Scenes/0_MainScene.unity | 2 + Game/Assets/Scripts/DamageHandler.cs | 36 +++++-- 3 files changed, 149 insertions(+), 10 deletions(-) diff --git a/Game/Assets/Prefabs/PlayerDroplet.prefab b/Game/Assets/Prefabs/PlayerDroplet.prefab index f76e71a..4675e23 100644 --- a/Game/Assets/Prefabs/PlayerDroplet.prefab +++ b/Game/Assets/Prefabs/PlayerDroplet.prefab @@ -15,6 +15,8 @@ GameObject: - component: {fileID: -8535381027169538} - component: {fileID: 5971260404453589572} - component: {fileID: 4218697106962905645} + - component: {fileID: -2923017547529843297} + - component: {fileID: 6923417058730395781} m_Layer: 0 m_Name: PlayerDroplet m_TagString: Player @@ -189,6 +191,7 @@ MonoBehaviour: dashingCooldown: 1 tr: {fileID: 0} animator: {fileID: 4218697106962905645} + fallingAnimationVelocityThreshold: 3 --- !u!111 &5971260404453589572 Animation: m_ObjectHideFlags: 0 @@ -229,3 +232,121 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!82 &-2923017547529843297 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2141180002423843430} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 8300000, guid: a2bc0335c81b4244397158d9fcb5f586, type: 3} + m_PlayOnAwake: 0 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!114 &6923417058730395781 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2141180002423843430} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2b3b9fc97a2d39d2d84c4be43a79247a, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::DamageHandler + threshold: 12 + multiplier: 0.1 + maxHealth: 1 + health: 0 + minSize: 0.4 + maxFallingTime: 2 + fallingAnimTreshold: 0.2 + speaker: {fileID: -2923017547529843297} + fallsound: {fileID: 8300000, guid: a2bc0335c81b4244397158d9fcb5f586, type: 3} diff --git a/Game/Assets/Scenes/0_MainScene.unity b/Game/Assets/Scenes/0_MainScene.unity index 05e8035..3e9993c 100644 --- a/Game/Assets/Scenes/0_MainScene.unity +++ b/Game/Assets/Scenes/0_MainScene.unity @@ -4146,6 +4146,8 @@ MonoBehaviour: minSize: 0.4 maxFallingTime: 2 fallingAnimTreshold: 0.2 + speaker: {fileID: 0} + fallsound: {fileID: 0} --- !u!1001 &687478031 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Game/Assets/Scripts/DamageHandler.cs b/Game/Assets/Scripts/DamageHandler.cs index 91a8d49..ec6db82 100644 --- a/Game/Assets/Scripts/DamageHandler.cs +++ b/Game/Assets/Scripts/DamageHandler.cs @@ -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) {