basic sounds and music

This commit is contained in:
MrTorex committed 2026-02-03 20:22:33 +03:00
1 parent 8219685d00
commit 3938d93241
16 files changed
+389

No files matched your search

@@ -17,6 +17,8 @@ namespace Code.Gameplay.Player
[SerializeField] private LayerMask _enemyLayer; [SerializeField] private LayerMask _enemyLayer;
[SerializeField] private Slider _healthBar; [SerializeField] private Slider _healthBar;
[SerializeField] private AudioSource audioSource;
private int _currentHealth; private int _currentHealth;
private bool _isInvincible; private bool _isInvincible;
@@ -24,6 +26,8 @@ namespace Code.Gameplay.Player
private float _lastAttackTime; private float _lastAttackTime;
public float nextAttackTime => _lastAttackTime + _attackCooldown; public float nextAttackTime => _lastAttackTime + _attackCooldown;
private AudioClip _attackClip;
public event Action<int> OnHealthChanged; public event Action<int> OnHealthChanged;
public event Action OnDied; public event Action OnDied;
public event Action OnTookDamage; public event Action OnTookDamage;
@@ -34,6 +38,7 @@ namespace Code.Gameplay.Player
private void Start() private void Start()
{ {
_attackClip = Resources.Load<AudioClip>("Audio/SFX/AttackSFX");
_currentHealth = _maxHealth; _currentHealth = _maxHealth;
OnHealthChanged?.Invoke(_currentHealth); OnHealthChanged?.Invoke(_currentHealth);
} }
@@ -70,6 +75,7 @@ namespace Code.Gameplay.Player
_lastAttackTime = Time.time; _lastAttackTime = Time.time;
OnAttacked?.Invoke(); OnAttacked?.Invoke();
audioSource.PlayOneShot(_attackClip);
var hits = Physics2D.OverlapCircleAll(transform.position, _attackRange, _enemyLayer); var hits = Physics2D.OverlapCircleAll(transform.position, _attackRange, _enemyLayer);
foreach (var hit in hits) foreach (var hit in hits)
@@ -21,6 +21,9 @@ namespace Code.Gameplay.Player
[SerializeField] private float _groundCheckRadius = 0.2f; [SerializeField] private float _groundCheckRadius = 0.2f;
[SerializeField] private float _jumpDuration = 0.5f; [SerializeField] private float _jumpDuration = 0.5f;
[SerializeField] private float _sprintPitchMultiplier = 1.2f;
[SerializeField] private AudioSource audioSource;
private IInputService _input; private IInputService _input;
private bool _isJumping; private bool _isJumping;
@@ -32,6 +35,11 @@ namespace Code.Gameplay.Player
private RuntimeAnimatorController _walkAnimator; private RuntimeAnimatorController _walkAnimator;
private RuntimeAnimatorController _jumpAnimator; private RuntimeAnimatorController _jumpAnimator;
private RuntimeAnimatorController _attackAnimator; private RuntimeAnimatorController _attackAnimator;
private AudioClip _jumpClip;
private AudioClip _walkClip;
private bool _wasMovingLastFrame;
public bool isGrounded { get; private set; } public bool isGrounded { get; private set; }
@@ -43,6 +51,8 @@ namespace Code.Gameplay.Player
_walkAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_walk_01"); _walkAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_walk_01");
_jumpAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_jump_01"); _jumpAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_jump_01");
_attackAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_atack_01"); _attackAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_atack_01");
_jumpClip = Resources.Load<AudioClip>("Audio/SFX/JumpSFX");
_walkClip = Resources.Load<AudioClip>("Audio/SFX/WalkSFX");
_playerHealth.OnTookDamage += StartBlinking; _playerHealth.OnTookDamage += StartBlinking;
} }
@@ -69,6 +79,7 @@ namespace Code.Gameplay.Player
{ {
case true when isGrounded: case true when isGrounded:
_isJumping = true; _isJumping = true;
audioSource.PlayOneShot(_jumpClip);
_jumpTimer = 0f; _jumpTimer = 0f;
_rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce); _rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce);
break; break;
@@ -142,10 +153,23 @@ namespace Code.Gameplay.Player
private void Move() private void Move()
{ {
var moveInput = _input.MoveInput; var moveInput = _input.MoveInput;
var isMoving = Mathf.Abs(moveInput) > 0.1f;
var speed = _input.SprintHeld ? _moveSpeed * _sprintSpeedMultiplier : _moveSpeed; var speed = _input.SprintHeld ? _moveSpeed * _sprintSpeedMultiplier : _moveSpeed;
var targetVelocityX = moveInput * speed; var targetVelocityX = moveInput * speed;
_rb.linearVelocity = new Vector2(targetVelocityX, _rb.linearVelocity.y); _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() private void HandleJump()
+3
View File
@@ -16,6 +16,7 @@ namespace Code.UI
[SerializeField] private TMP_Text deathText; [SerializeField] private TMP_Text deathText;
[SerializeField] private Button exitButton; [SerializeField] private Button exitButton;
[SerializeField] private PlayerHealth playerHealth; [SerializeField] private PlayerHealth playerHealth;
[SerializeField] private AudioSource audioSource;
private IInputService _inputService; private IInputService _inputService;
@@ -34,6 +35,8 @@ namespace Code.UI
private void HandleDeath() private void HandleDeath()
{ {
var clip = Resources.Load<AudioClip>("Audio/SFX/DeathSFX");
audioSource.PlayOneShot(clip);
_inputService.DisableMap(ActionMapping.Gameplay); _inputService.DisableMap(ActionMapping.Gameplay);
deathScreen.gameObject.SetActive(true); deathScreen.gameObject.SetActive(true);
Binary file not shown.
@@ -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:
Binary file not shown.
@@ -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:
Binary file not shown.
@@ -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:
Binary file not shown.
@@ -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:
Binary file not shown.
@@ -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:
Binary file not shown.
@@ -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:
+200
View File
@@ -2163,6 +2163,7 @@ MonoBehaviour:
deathText: {fileID: 417979273} deathText: {fileID: 417979273}
exitButton: {fileID: 254654570} exitButton: {fileID: 254654570}
playerHealth: {fileID: 1616841237} playerHealth: {fileID: 1616841237}
audioSource: {fileID: 519420034}
--- !u!1 &294403282 --- !u!1 &294403282
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -3373,6 +3374,7 @@ GameObject:
- component: {fileID: 519420029} - component: {fileID: 519420029}
- component: {fileID: 519420030} - component: {fileID: 519420030}
- component: {fileID: 519420033} - component: {fileID: 519420033}
- component: {fileID: 519420034}
m_Layer: 3 m_Layer: 3
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
@@ -3520,6 +3522,103 @@ MonoBehaviour:
_useVerticalBounds: 1 _useVerticalBounds: 1
_minY: -5 _minY: -5
_maxY: 20 _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 --- !u!1 &521083952
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -11427,6 +11526,7 @@ GameObject:
- component: {fileID: 1616841234} - component: {fileID: 1616841234}
- component: {fileID: 1616841236} - component: {fileID: 1616841236}
- component: {fileID: 1616841237} - component: {fileID: 1616841237}
- component: {fileID: 1616841238}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
m_TagString: Player m_TagString: Player
@@ -11561,6 +11661,8 @@ MonoBehaviour:
_jumpForce: 25 _jumpForce: 25
_groundCheckRadius: 0.3 _groundCheckRadius: 0.3
_jumpDuration: 0.5 _jumpDuration: 0.5
_sprintPitchMultiplier: 1.5
audioSource: {fileID: 1616841238}
--- !u!61 &1616841235 --- !u!61 &1616841235
BoxCollider2D: BoxCollider2D:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -11650,6 +11752,104 @@ MonoBehaviour:
serializedVersion: 2 serializedVersion: 2
m_Bits: 64 m_Bits: 64
_healthBar: {fileID: 1475998710} _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 --- !u!1 &1674212219
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0