92 lines
2.1 KiB
C#
92 lines
2.1 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDK3.UdonNetworkCalling;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class UniversallyChallengedManager : UdonSharpBehaviour
|
|
{
|
|
[UdonSynced] public bool isBuzzersEnabled = false;
|
|
[UdonSynced] public bool areSirensActivated = false;
|
|
|
|
public Light[] lights;
|
|
public AudioSource sirenAudioSource;
|
|
public Animator[] turretAnimators;
|
|
|
|
public void EnableBuzzers()
|
|
{
|
|
isBuzzersEnabled = true;
|
|
RequestSerialization();
|
|
}
|
|
|
|
public void HandleSirenButton()
|
|
{
|
|
areSirensActivated = !areSirensActivated;
|
|
UpdateLights();
|
|
HandleAudio();
|
|
RequestSerialization();
|
|
}
|
|
|
|
private void HandleAudio()
|
|
{
|
|
if (sirenAudioSource != null)
|
|
{
|
|
if (areSirensActivated)
|
|
{
|
|
sirenAudioSource.Play();
|
|
}
|
|
else
|
|
{
|
|
sirenAudioSource.Stop();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateLights()
|
|
{
|
|
for (int i = 0; i < lights.Length; i++)
|
|
{
|
|
lights[i].intensity = areSirensActivated ? 50f : 0f;
|
|
}
|
|
}
|
|
|
|
public override void OnDeserialization()
|
|
{
|
|
UpdateLights();
|
|
// Only sync audio if this is not the owner (owner already plays it in HandleSirenButton)
|
|
if (!Networking.IsOwner(gameObject))
|
|
{
|
|
HandleAudio();
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (areSirensActivated)
|
|
{
|
|
for (int i = 0; i < lights.Length; i++)
|
|
{
|
|
lights[i].transform.rotation *= Quaternion.Euler(0, Time.deltaTime * 200f, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void HandleGunButtonPress()
|
|
{
|
|
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "ActivateGunTurrets");
|
|
}
|
|
|
|
[NetworkCallable]
|
|
public void ActivateGunTurrets()
|
|
{
|
|
if (turretAnimators != null)
|
|
{
|
|
for (int i = 0; i < turretAnimators.Length; i++)
|
|
{
|
|
turretAnimators[i].SetTrigger("StartGunLower");
|
|
}
|
|
}
|
|
}
|
|
}
|