Commit uncommited stuff I was missing like an idiot
This commit is contained in:
parent
6efd2653a1
commit
9e4ab5f7a3
37 changed files with 3055 additions and 1 deletions
62
Assets/Scripts/Counters/StoveCounterSound.cs
Normal file
62
Assets/Scripts/Counters/StoveCounterSound.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StoveCounterSound : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private StoveCounter stoveCounter;
|
||||
|
||||
|
||||
private AudioSource audioSource;
|
||||
private float warningSoundTimer;
|
||||
private bool playWarningSound;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
stoveCounter.OnStateChanged += StoveCounter_OnStateChanged;
|
||||
stoveCounter.OnProgressChange += StoveCounter_OnProgressChange;
|
||||
}
|
||||
|
||||
private void StoveCounter_OnProgressChange(object sender, IHasProgress.OnProgressChangeEventsArgs e)
|
||||
{
|
||||
float burnShowProgressAmount = .5f;
|
||||
playWarningSound = stoveCounter.IsFried() && e.progressNormalized >= burnShowProgressAmount;
|
||||
}
|
||||
|
||||
private void StoveCounter_OnStateChanged(object sender, StoveCounter.OnStateChangedEventArgs e)
|
||||
{
|
||||
bool playSound = e.state == StoveCounter.State.Frying || e.state == StoveCounter.State.Fried;
|
||||
|
||||
if (playSound)
|
||||
{
|
||||
audioSource.Play();
|
||||
} else
|
||||
{
|
||||
audioSource.Pause();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
if (playWarningSound) {
|
||||
warningSoundTimer -= Time.deltaTime;
|
||||
|
||||
if (warningSoundTimer <= 0f)
|
||||
{
|
||||
float warningSoundTimerMax = .3f;
|
||||
warningSoundTimer = warningSoundTimerMax;
|
||||
|
||||
SoundManager.Instance.PlayWarningSound(stoveCounter.transform.position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue