completed sounds
This commit is contained in:
1 parent
3938d93241
commit
be3defc280
12 files changed
+1084
-22
No files matched your search
@@ -16,13 +16,18 @@ namespace Code.Gameplay.Enemies
|
||||
[SerializeField] private float _blinkDuration = 0.2f;
|
||||
[SerializeField] private Color _hitColor = Color.red;
|
||||
|
||||
[SerializeField] private AudioSource _audioSource;
|
||||
|
||||
private Color _originalColor;
|
||||
|
||||
private Vector3 _startPosition;
|
||||
private bool _facingRight = true;
|
||||
|
||||
private AudioClip _deathClip;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_deathClip = Resources.Load<AudioClip>("Audio/SFX/BirdDeathSFX");
|
||||
_startPosition = transform.position;
|
||||
}
|
||||
|
||||
@@ -93,6 +98,7 @@ namespace Code.Gameplay.Enemies
|
||||
|
||||
private void Die()
|
||||
{
|
||||
_audioSource.PlayOneShot(_deathClip);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Code.Gameplay.Player
|
||||
public float nextAttackTime => _lastAttackTime + _attackCooldown;
|
||||
|
||||
private AudioClip _attackClip;
|
||||
private AudioClip _damageClip;
|
||||
|
||||
public event Action<int> OnHealthChanged;
|
||||
public event Action OnDied;
|
||||
@@ -39,6 +40,7 @@ namespace Code.Gameplay.Player
|
||||
private void Start()
|
||||
{
|
||||
_attackClip = Resources.Load<AudioClip>("Audio/SFX/AttackSFX");
|
||||
_damageClip = Resources.Load<AudioClip>("Audio/SFX/DamageSFX");
|
||||
_currentHealth = _maxHealth;
|
||||
OnHealthChanged?.Invoke(_currentHealth);
|
||||
}
|
||||
@@ -59,6 +61,7 @@ namespace Code.Gameplay.Player
|
||||
_currentHealth -= _damageFromEnemy;
|
||||
OnHealthChanged?.Invoke(_currentHealth);
|
||||
OnTookDamage?.Invoke();
|
||||
audioSource.PlayOneShot(_damageClip);
|
||||
|
||||
if (_currentHealth <= 0)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace Code.Gameplay.Player
|
||||
[SerializeField] private float _jumpDuration = 0.5f;
|
||||
[SerializeField] private float _sprintPitchMultiplier = 1.2f;
|
||||
|
||||
[SerializeField] private AudioSource audioSource;
|
||||
[SerializeField] private AudioSource walkAudioSource;
|
||||
[SerializeField] private AudioSource jumpAudioSource;
|
||||
|
||||
private IInputService _input;
|
||||
private bool _isJumping;
|
||||
@@ -38,8 +39,6 @@ namespace Code.Gameplay.Player
|
||||
|
||||
private AudioClip _jumpClip;
|
||||
private AudioClip _walkClip;
|
||||
|
||||
private bool _wasMovingLastFrame;
|
||||
|
||||
public bool isGrounded { get; private set; }
|
||||
|
||||
@@ -79,7 +78,7 @@ namespace Code.Gameplay.Player
|
||||
{
|
||||
case true when isGrounded:
|
||||
_isJumping = true;
|
||||
audioSource.PlayOneShot(_jumpClip);
|
||||
jumpAudioSource.PlayOneShot(_jumpClip);
|
||||
_jumpTimer = 0f;
|
||||
_rb.linearVelocity = new Vector2(_rb.linearVelocity.x, _jumpForce);
|
||||
break;
|
||||
@@ -159,17 +158,24 @@ namespace Code.Gameplay.Player
|
||||
|
||||
_rb.linearVelocity = new Vector2(targetVelocityX, _rb.linearVelocity.y);
|
||||
|
||||
// Проигрываем звук ходьбы ТОЛЬКО при начале движения
|
||||
if (isMoving && !_wasMovingLastFrame && isGrounded)
|
||||
if (isMoving && isGrounded)
|
||||
{
|
||||
if (_walkClip)
|
||||
if (_walkClip && walkAudioSource)
|
||||
{
|
||||
audioSource.pitch = _input.SprintHeld ? _sprintPitchMultiplier : 1f;
|
||||
audioSource.PlayOneShot(_walkClip);
|
||||
walkAudioSource.pitch = _input.SprintHeld ? _sprintPitchMultiplier : 1f;
|
||||
if (walkAudioSource.clip != _walkClip)
|
||||
{
|
||||
walkAudioSource.clip = _walkClip;
|
||||
walkAudioSource.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_wasMovingLastFrame = isMoving;
|
||||
else
|
||||
{
|
||||
walkAudioSource.Stop();
|
||||
walkAudioSource.pitch = 1;
|
||||
walkAudioSource.clip = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleJump()
|
||||
@@ -185,12 +191,12 @@ namespace Code.Gameplay.Player
|
||||
|
||||
private async void StartBlinking()
|
||||
{
|
||||
_spriteRenderer.color = new Color(1, 1, 1, 0.5f); // полупрозрачность
|
||||
float blinkDuration = 2f;
|
||||
float blinkInterval = 0.1f;
|
||||
int blinkCount = (int)(blinkDuration / blinkInterval);
|
||||
_spriteRenderer.color = new Color(1, 1, 1, 0.5f);
|
||||
const float blinkDuration = 2f;
|
||||
const float blinkInterval = 0.1f;
|
||||
var blinkCount = (int)(blinkDuration / blinkInterval);
|
||||
|
||||
for (int i = 0; i < blinkCount; i++)
|
||||
for (var i = 0; i < blinkCount; i++)
|
||||
{
|
||||
_spriteRenderer.enabled = !_spriteRenderer.enabled;
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(blinkInterval));
|
||||
|
||||
Reference in new issue
Block a user