basic sounds and music
This commit is contained in:
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 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<int> OnHealthChanged;
|
||||
public event Action OnDied;
|
||||
public event Action OnTookDamage;
|
||||
@@ -34,6 +38,7 @@ namespace Code.Gameplay.Player
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_attackClip = Resources.Load<AudioClip>("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)
|
||||
|
||||
@@ -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<RuntimeAnimatorController>("Animations/penguin_walk_01");
|
||||
_jumpAnimator = Resources.Load<RuntimeAnimatorController>("Animations/penguin_jump_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;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<AudioClip>("Audio/SFX/DeathSFX");
|
||||
audioSource.PlayOneShot(clip);
|
||||
_inputService.DisableMap(ActionMapping.Gameplay);
|
||||
deathScreen.gameObject.SetActive(true);
|
||||
|
||||
|
||||
Reference in new issue
Block a user