basic sounds and music
This commit is contained in:
1 parent
8219685d00
commit
3938d93241
16 files changed
+389
No files matched your search
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user