Add SFX and SFX logic
This commit is contained in:
parent
f0e4f6c9ba
commit
1aa97baff4
19 changed files with 504 additions and 8 deletions
33
Assets/Scripts/StoveCounterSound.cs
Normal file
33
Assets/Scripts/StoveCounterSound.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class StoveCounterSound : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private StoveCounter stoveCounter;
|
||||
private AudioSource audioSource;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
stoveCounter.OnStateChanged += StoveCounter_OnStateChanged;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue