61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using UnityEngine;
|
|
|
|
namespace _Project.Scripts.PlayerUtils
|
|
{
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class PlayerSound : MonoBehaviour
|
|
{
|
|
[Header("Настройки AudioSource")]
|
|
[SerializeField] private AudioSource audioSource;
|
|
|
|
[Header("Звуки Передвижения")]
|
|
[SerializeField] private AudioClip[] footstepSounds;
|
|
[SerializeField] private AudioClip jumpSound;
|
|
[SerializeField] private AudioClip landSound;
|
|
[SerializeField] private AudioClip slideSound;
|
|
|
|
[Header("Звуки Оружия")]
|
|
[SerializeField] private AudioClip shootSound;
|
|
|
|
private void Reset()
|
|
{
|
|
// Автоматически подцепит AudioSource при добавлении скрипта на объект
|
|
audioSource = GetComponent<AudioSource>();
|
|
}
|
|
|
|
public void PlayFootstep(bool isSprinting)
|
|
{
|
|
if (footstepSounds == null || footstepSounds.Length == 0) return;
|
|
|
|
int randomIndex = Random.Range(0, footstepSounds.Length);
|
|
|
|
// Немного меняем высоту звука для разнообразия
|
|
audioSource.pitch = Random.Range(0.9f, 1.1f);
|
|
|
|
float volume = isSprinting ? 0.6f : 0.4f;
|
|
audioSource.PlayOneShot(footstepSounds[randomIndex], volume);
|
|
|
|
audioSource.pitch = 1f; // Сбрасываем питч обратно
|
|
}
|
|
|
|
public void PlayJump()
|
|
{
|
|
if (jumpSound != null) audioSource.PlayOneShot(jumpSound, 0.7f);
|
|
}
|
|
|
|
public void PlayLand()
|
|
{
|
|
if (landSound != null) audioSource.PlayOneShot(landSound, 0.5f);
|
|
}
|
|
|
|
public void PlaySlide()
|
|
{
|
|
if (slideSound != null) audioSource.PlayOneShot(slideSound, 0.7f);
|
|
}
|
|
|
|
public void PlayShoot()
|
|
{
|
|
if (shootSound != null) audioSource.PlayOneShot(shootSound, 0.8f);
|
|
}
|
|
}
|
|
} |