forked from cgvr/DeltaVR
		
	
		
			
				
	
	
		
			43 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Collections;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Runtime.Remoting.Messaging;
 | 
						|
using UnityEngine;
 | 
						|
using UnityEngine.PlayerLoop;
 | 
						|
using UnityEngine.XR.Content.Interaction;
 | 
						|
 | 
						|
public class AlarmTrigger : MonoBehaviour
 | 
						|
{
 | 
						|
    public XRPushButton PushButton;
 | 
						|
    public AudioSource AlarmSequence;
 | 
						|
    public AudioSource VentilationSequence;
 | 
						|
    private bool hasAlarm = false;
 | 
						|
 | 
						|
    void Start()
 | 
						|
    {
 | 
						|
        if (PushButton != null)
 | 
						|
        {
 | 
						|
            PushButton.onPress.AddListener(OnButtonPressed);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    void OnButtonPressed()
 | 
						|
    {
 | 
						|
        Debug.Log("Alarm button Pressed!");
 | 
						|
        
 | 
						|
        if (!AlarmSequence.isPlaying) { //if alarm isn't already triggered.
 | 
						|
            VentilationSequence.Stop();
 | 
						|
            AlarmSequence.Play();
 | 
						|
            hasAlarm = true;
 | 
						|
        }
 | 
						|
    }
 | 
						|
    void Update()
 | 
						|
    {
 | 
						|
        if(hasAlarm && !AlarmSequence.isPlaying) // If alarm state has ended.
 | 
						|
        {
 | 
						|
            VentilationSequence.Play(); // Return to normal.
 | 
						|
            hasAlarm = false;   
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
}
 |