*
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
public class DoorAudioController : MonoBehaviour {
|
||||
private Door _door;
|
||||
private AudioSource _audio;
|
||||
public AudioClip openSound;
|
||||
public AudioClip closeSound;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
_door = transform.parent.GetComponentInChildren<Door>();
|
||||
_door.StateChanged += HandleStateChanged;
|
||||
|
||||
_audio = GetComponent<AudioSource>();
|
||||
|
||||
}
|
||||
|
||||
void HandleStateChanged (Door sender, DoorState from, DoorState to)
|
||||
{
|
||||
if(from == DoorState.Closed){
|
||||
_audio.PlayOneShot(openSound);
|
||||
}else if(to == DoorState.Closed){
|
||||
_audio.PlayOneShot(closeSound);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user