34 lines
712 B
C#
34 lines
712 B
C#
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 () {
|
|
|
|
}
|
|
}
|