Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(AudioSource))]
- public class Alarm : MonoBehaviour
- {
- private AudioSource AlarmSound;
- [SerializeField] private AudioSource _audiosource;
- private bool _volFull = false;
- private void Awake()
- {
- AlarmSound = GetComponent<AudioSource>();
- AlarmSound.volume = 0.01f;
- }
- private void OnTriggerEnter()
- {
- AlarmSound.Play();
- }
- private void OnTriggerExit()
- {
- AlarmSound.Stop();
- }
- private void Update()
- {
- float elapsedTime = Time.deltaTime;
- if (AlarmSound.volume <= 1 && _volFull == false)
- {
- AlarmSound.volume += elapsedTime;
- if (AlarmSound.volume >= 0.99f)
- {
- _volFull = true;
- }
- }
- if (_volFull == true)
- {
- AlarmSound.volume -= elapsedTime;
- if (AlarmSound.volume == 0f)
- {
- _volFull = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement