/
arti4
/
CourseWork
Обзор
Документация
Войти
/
arti4
/
CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Scriptes/FireBarrel.cs
58 строк
2 KB
arti4
Загрузить файлы в «Scriptes»
01 июн 2025, 11:57
01 июн 2025, 11:57
9c49e8f
Код
Авторство
О чём код?
using UnityEngine; public class FireBarrel : MonoBehaviour { [SerializeField] private AudioSource audioSource; [SerializeField] private AudioClip fireSound; public float maxHearingDistance = 10f; private Transform player; private void Start() { GameObject playerObject = GameObject.FindGameObjectWithTag("Player"); if (playerObject != null) { player = playerObject.transform; } if (audioSource != null && fireSound != null) { audioSource.clip = fireSound; audioSource.loop = true; audioSource.Play(); } } private void Update() { AdjustSoundVolume(); } //��������� ��������� � ����������� �� ���������� �� ������ private void AdjustSoundVolume() { if (audioSource == null || player == null) return; float distance = Vector2.Distance(transform.position, player.position); if (distance > maxHearingDistance) { audioSource.volume = 0; return; } if (distance <= maxHearingDistance / 2) { audioSource.volume = 1; return; } float volumeFactor = Mathf.Clamp01(1 - ((distance - (maxHearingDistance / 2)) / (maxHearingDistance / 2))); audioSource.volume = volumeFactor; } //������ ���������� ��� ������� private void OnDrawGizmosSelected() { Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position, maxHearingDistance); } }