Adding server room sound effects and button to trigger them
This commit is contained in:
39
Assets/_PROJECT/Components/Server room/Alarm Trigger.cs
Normal file
39
Assets/_PROJECT/Components/Server room/Alarm Trigger.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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!");
|
||||
VentilationSequence.Stop();
|
||||
AlarmSequence.Play();
|
||||
hasAlarm = true;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if(hasAlarm && !AlarmSequence.isPlaying) // If alarm state has ended.
|
||||
{
|
||||
VentilationSequence.Play(); // Return to normal.
|
||||
hasAlarm = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user