// Update is called once per frame void Update() { if (lastTriggerState != trigger.GetTriggerState()) { lastTriggerState = trigger.GetTriggerState(); if (lastTriggerState) { //play open if (sfxActivated != null) { audio.clip = sfxActivated; } } else { //play close if (sfxDeactivated != null) { audio.clip = sfxDeactivated; } } audio.Play(); } }
// Use this for initialization void Start() { trigger = GetComponent <DoorTrigger>(); lastTriggerState = trigger.GetTriggerState(); }