From 3938d9324123e191bc81324862f294497c036177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C5=A1a=20Ceviel?= Date: Tue, 3 Feb 2026 20:22:33 +0300 Subject: [PATCH] basic sounds and music --- Assets/Code/Gameplay/Player/PlayerHealth.cs | 6 + Assets/Code/Gameplay/Player/PlayerMovement.cs | 24 +++ Assets/Code/UI/GameplayController.cs | 3 + Assets/Resources/Audio/Music/Level1Theme.ogg | 3 + .../Audio/Music/Level1Theme.ogg.meta | 23 ++ Assets/Resources/Audio/Music/Level2Theme.ogg | 3 + .../Audio/Music/Level2Theme.ogg.meta | 23 ++ Assets/Resources/Audio/SFX/AttackSFX.mp3 | 3 + Assets/Resources/Audio/SFX/AttackSFX.mp3.meta | 23 ++ Assets/Resources/Audio/SFX/DeathSFX.mp3 | 3 + Assets/Resources/Audio/SFX/DeathSFX.mp3.meta | 23 ++ Assets/Resources/Audio/SFX/JumpSFX.mp3 | 3 + Assets/Resources/Audio/SFX/JumpSFX.mp3.meta | 23 ++ Assets/Resources/Audio/SFX/WalkSFX.mp3 | 3 + Assets/Resources/Audio/SFX/WalkSFX.mp3.meta | 23 ++ Assets/Resources/Scenes/Gameplay.unity | 200 ++++++++++++++++++ 16 files changed, 389 insertions(+) create mode 100644 Assets/Resources/Audio/Music/Level1Theme.ogg create mode 100644 Assets/Resources/Audio/Music/Level1Theme.ogg.meta create mode 100644 Assets/Resources/Audio/Music/Level2Theme.ogg create mode 100644 Assets/Resources/Audio/Music/Level2Theme.ogg.meta create mode 100644 Assets/Resources/Audio/SFX/AttackSFX.mp3 create mode 100644 Assets/Resources/Audio/SFX/AttackSFX.mp3.meta create mode 100644 Assets/Resources/Audio/SFX/DeathSFX.mp3 create mode 100644 Assets/Resources/Audio/SFX/DeathSFX.mp3.meta create mode 100644 Assets/Resources/Audio/SFX/JumpSFX.mp3 create mode 100644 Assets/Resources/Audio/SFX/JumpSFX.mp3.meta create mode 100644 Assets/Resources/Audio/SFX/WalkSFX.mp3 create mode 100644 Assets/Resources/Audio/SFX/WalkSFX.mp3.meta diff --git a/Assets/Code/Gameplay/Player/PlayerHealth.cs b/Assets/Code/Gameplay/Player/PlayerHealth.cs index 5694bd5..44a5085 100644 --- a/Assets/Code/Gameplay/Player/PlayerHealth.cs +++ b/Assets/Code/Gameplay/Player/PlayerHealth.cs @@ -17,6 +17,8 @@ namespace Code.Gameplay.Player [SerializeField] private LayerMask _enemyLayer; [SerializeField] private Slider _healthBar; + + [SerializeField] private AudioSource audioSource; private int _currentHealth; private bool _isInvincible; @@ -24,6 +26,8 @@ namespace Code.Gameplay.Player private float _lastAttackTime; public float nextAttackTime => _lastAttackTime + _attackCooldown; + private AudioClip _attackClip; + public event Action OnHealthChanged; public event Action OnDied; public event Action OnTookDamage; @@ -34,6 +38,7 @@ namespace Code.Gameplay.Player private void Start() { + _attackClip = Resources.Load("Audio/SFX/AttackSFX"); _currentHealth = _maxHealth; OnHealthChanged?.Invoke(_currentHealth); } @@ -70,6 +75,7 @@ namespace Code.Gameplay.Player _lastAttackTime = Time.time; OnAttacked?.Invoke(); + audioSource.PlayOneShot(_attackClip); var hits = Physics2D.OverlapCircleAll(transform.position, _attackRange, _enemyLayer); foreach (var hit in hits) diff --git a/Assets/Code/Gameplay/Player/PlayerMovement.cs b/Assets/Code/Gameplay/Player/PlayerMovement.cs index e9d98e6..f0b06ec 100644 --- a/Assets/Code/Gameplay/Player/PlayerMovement.cs +++ b/Assets/Code/Gameplay/Player/PlayerMovement.cs @@ -21,6 +21,9 @@ namespace Code.Gameplay.Player [SerializeField] private float _groundCheckRadius = 0.2f; [SerializeField] private float _jumpDuration = 0.5f; + [SerializeField] private float _sprintPitchMultiplier = 1.2f; + + [SerializeField] private AudioSource audioSource; private IInputService _input; private bool _isJumping; @@ -32,6 +35,11 @@ namespace Code.Gameplay.Player private RuntimeAnimatorController _walkAnimator; private RuntimeAnimatorController _jumpAnimator; private RuntimeAnimatorController _attackAnimator; + + private AudioClip _jumpClip; + private AudioClip _walkClip; + + private bool _wasMovingLastFrame; public bool isGrounded { get; private set; } @@ -43,6 +51,8 @@ namespace Code.Gameplay.Player _walkAnimator = Resources.Load("Animations/penguin_walk_01"); _jumpAnimator = Resources.Load("Animations/penguin_jump_01"); _attackAnimator = Resources.Load("Animations/penguin_atack_01"); + _jumpClip = Resources.Load("Audio/SFX/JumpSFX"); + _walkClip = Resources.Load("Audio/SFX/WalkSFX"); _playerHealth.OnTookDamage += StartBlinking; } @@ -69,6 +79,7 @@ namespace Code.Gameplay.Player { case true when isGrounded: _isJumping = true; + audioSource.PlayOneShot(_jumpClip); _jumpTimer = 0f; _rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce); break; @@ -142,10 +153,23 @@ namespace Code.Gameplay.Player private void Move() { var moveInput = _input.MoveInput; + var isMoving = Mathf.Abs(moveInput) > 0.1f; var speed = _input.SprintHeld ? _moveSpeed * _sprintSpeedMultiplier : _moveSpeed; var targetVelocityX = moveInput * speed; _rb.linearVelocity = new Vector2(targetVelocityX, _rb.linearVelocity.y); + + // Проигрываем звук ходьбы ТОЛЬКО при начале движения + if (isMoving && !_wasMovingLastFrame && isGrounded) + { + if (_walkClip) + { + audioSource.pitch = _input.SprintHeld ? _sprintPitchMultiplier : 1f; + audioSource.PlayOneShot(_walkClip); + } + } + + _wasMovingLastFrame = isMoving; } private void HandleJump() diff --git a/Assets/Code/UI/GameplayController.cs b/Assets/Code/UI/GameplayController.cs index 1a4009f..1170591 100644 --- a/Assets/Code/UI/GameplayController.cs +++ b/Assets/Code/UI/GameplayController.cs @@ -16,6 +16,7 @@ namespace Code.UI [SerializeField] private TMP_Text deathText; [SerializeField] private Button exitButton; [SerializeField] private PlayerHealth playerHealth; + [SerializeField] private AudioSource audioSource; private IInputService _inputService; @@ -34,6 +35,8 @@ namespace Code.UI private void HandleDeath() { + var clip = Resources.Load("Audio/SFX/DeathSFX"); + audioSource.PlayOneShot(clip); _inputService.DisableMap(ActionMapping.Gameplay); deathScreen.gameObject.SetActive(true); diff --git a/Assets/Resources/Audio/Music/Level1Theme.ogg b/Assets/Resources/Audio/Music/Level1Theme.ogg new file mode 100644 index 0000000..794b81e --- /dev/null +++ b/Assets/Resources/Audio/Music/Level1Theme.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:995ae51efc737cb01f1fa0df26150b79d9bc88dda8b98a2823da792dbf9fd350 +size 5461632 diff --git a/Assets/Resources/Audio/Music/Level1Theme.ogg.meta b/Assets/Resources/Audio/Music/Level1Theme.ogg.meta new file mode 100644 index 0000000..53ff7ab --- /dev/null +++ b/Assets/Resources/Audio/Music/Level1Theme.ogg.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 5e7fe4e18403f02089f50eee01e5e024 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/Music/Level2Theme.ogg b/Assets/Resources/Audio/Music/Level2Theme.ogg new file mode 100644 index 0000000..602da5f --- /dev/null +++ b/Assets/Resources/Audio/Music/Level2Theme.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96e071f953336a57d3387372de6e504d182345ae966d8c23f67b4952bfb5a823 +size 2078281 diff --git a/Assets/Resources/Audio/Music/Level2Theme.ogg.meta b/Assets/Resources/Audio/Music/Level2Theme.ogg.meta new file mode 100644 index 0000000..9db46e7 --- /dev/null +++ b/Assets/Resources/Audio/Music/Level2Theme.ogg.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: b68769b212080605aab029cb63c3c5c8 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/SFX/AttackSFX.mp3 b/Assets/Resources/Audio/SFX/AttackSFX.mp3 new file mode 100644 index 0000000..0d2de09 --- /dev/null +++ b/Assets/Resources/Audio/SFX/AttackSFX.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f47471547658a8393075f38ed0366c22cc3babf136572e2b99d355f899b84a4 +size 16512 diff --git a/Assets/Resources/Audio/SFX/AttackSFX.mp3.meta b/Assets/Resources/Audio/SFX/AttackSFX.mp3.meta new file mode 100644 index 0000000..6d56827 --- /dev/null +++ b/Assets/Resources/Audio/SFX/AttackSFX.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 1960b554039a389f2b2fa430e3b035f7 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/SFX/DeathSFX.mp3 b/Assets/Resources/Audio/SFX/DeathSFX.mp3 new file mode 100644 index 0000000..c63d641 --- /dev/null +++ b/Assets/Resources/Audio/SFX/DeathSFX.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc9fc022bb3b2c1630df4e81bcb5befeacf74b2ebbd42ebb53d3c8bc85113b4e +size 124416 diff --git a/Assets/Resources/Audio/SFX/DeathSFX.mp3.meta b/Assets/Resources/Audio/SFX/DeathSFX.mp3.meta new file mode 100644 index 0000000..cbb9b73 --- /dev/null +++ b/Assets/Resources/Audio/SFX/DeathSFX.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 6f2e7e60f71b727599a55889a401f30e +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/SFX/JumpSFX.mp3 b/Assets/Resources/Audio/SFX/JumpSFX.mp3 new file mode 100644 index 0000000..7dc5fcd --- /dev/null +++ b/Assets/Resources/Audio/SFX/JumpSFX.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39efa000a45d05c623f79c9a08828fae3f7d049091f9074eff6d4ab641abc95e +size 12864 diff --git a/Assets/Resources/Audio/SFX/JumpSFX.mp3.meta b/Assets/Resources/Audio/SFX/JumpSFX.mp3.meta new file mode 100644 index 0000000..8659ffa --- /dev/null +++ b/Assets/Resources/Audio/SFX/JumpSFX.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 9eea6f9d1e05033bc8583d10cb876791 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Audio/SFX/WalkSFX.mp3 b/Assets/Resources/Audio/SFX/WalkSFX.mp3 new file mode 100644 index 0000000..cee55ee --- /dev/null +++ b/Assets/Resources/Audio/SFX/WalkSFX.mp3 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb5b4d5b701020392187ff0c51fc4ccc92f3af72863b764bdbcef4749d372a1d +size 4608 diff --git a/Assets/Resources/Audio/SFX/WalkSFX.mp3.meta b/Assets/Resources/Audio/SFX/WalkSFX.mp3.meta new file mode 100644 index 0000000..3efab6b --- /dev/null +++ b/Assets/Resources/Audio/SFX/WalkSFX.mp3.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: d9c1b95779dfd144dbfef79d67fd6637 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Scenes/Gameplay.unity b/Assets/Resources/Scenes/Gameplay.unity index 730163d..91a6d10 100644 --- a/Assets/Resources/Scenes/Gameplay.unity +++ b/Assets/Resources/Scenes/Gameplay.unity @@ -2163,6 +2163,7 @@ MonoBehaviour: deathText: {fileID: 417979273} exitButton: {fileID: 254654570} playerHealth: {fileID: 1616841237} + audioSource: {fileID: 519420034} --- !u!1 &294403282 GameObject: m_ObjectHideFlags: 0 @@ -3373,6 +3374,7 @@ GameObject: - component: {fileID: 519420029} - component: {fileID: 519420030} - component: {fileID: 519420033} + - component: {fileID: 519420034} m_Layer: 3 m_Name: Main Camera m_TagString: MainCamera @@ -3520,6 +3522,103 @@ MonoBehaviour: _useVerticalBounds: 1 _minY: -5 _maxY: 20 +--- !u!82 &519420034 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 519420028} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 8300000, guid: 5e7fe4e18403f02089f50eee01e5e024, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 1 + 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!1 &521083952 GameObject: m_ObjectHideFlags: 0 @@ -11427,6 +11526,7 @@ GameObject: - component: {fileID: 1616841234} - component: {fileID: 1616841236} - component: {fileID: 1616841237} + - component: {fileID: 1616841238} m_Layer: 0 m_Name: Player m_TagString: Player @@ -11561,6 +11661,8 @@ MonoBehaviour: _jumpForce: 25 _groundCheckRadius: 0.3 _jumpDuration: 0.5 + _sprintPitchMultiplier: 1.5 + audioSource: {fileID: 1616841238} --- !u!61 &1616841235 BoxCollider2D: m_ObjectHideFlags: 0 @@ -11650,6 +11752,104 @@ MonoBehaviour: serializedVersion: 2 m_Bits: 64 _healthBar: {fileID: 1475998710} + audioSource: {fileID: 1616841238} +--- !u!82 &1616841238 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1616841230} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 0} + m_PlayOnAwake: 1 + 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!1 &1674212219 GameObject: m_ObjectHideFlags: 0