ChargeRing Script (Patreon)
Content
Have fun with this one!
U#
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class ChargeRing1 : UdonSharpBehaviour
{
public UdonBehaviour controller1;
public UdonBehaviour controller2;
public UdonBehaviour controller3;
public UdonBehaviour controller4;
[SerializeField]
public ParticleSystem particle;
[SerializeField]
private float recastSecond = 5f;
private float recastTime = 0;
[UdonSynced]
public bool isActive = true;
[SerializeField]
private ParticleSystem chargeParticle;
private void OnTriggerEnter(Collider other)
{
if (other.GetType() == typeof(CharacterController) && isActive)
{
if (Networking.IsOwner(controller1.gameObject))
{
controller1.SendCustomEvent("ChargeEnergyToFull");
}
if (Networking.IsOwner(controller2.gameObject))
{
controller2.SendCustomEvent("ChargeEnergyToFull");
}
if (Networking.IsOwner(controller3.gameObject))
{
controller3.SendCustomEvent("ChargeEnergyToFull");
}
if (Networking.IsOwner(controller4.gameObject))
{
controller4.SendCustomEvent("ChargeEnergyToFull");
}
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "PlayParticle");
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.Owner, "SetRecast");
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "InactiveChargeRing");
}
}
public override void OnPlayerJoined(VRCPlayerApi player)
{
if (!player.isLocal)
{
return;
}
if (!isActive)
{
InactiveChargeRing();
}
}
private void Update()
{
if (Networking.LocalPlayer.IsOwner(this.gameObject))
{
if (!isActive)
{
recastTime -= Time.deltaTime;
if (recastTime <= 0)
{
isActive = true;
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.All, "ActiveChargeRing");
}
}
}
}
public void PlayParticle()
{
particle.Play();
}
public void ActiveChargeRing()
{
chargeParticle.Play();
}
public void InactiveChargeRing()
{
chargeParticle.Stop();
}
public void SetRecast()
{
recastTime = recastSecond;
isActive = false;
}
}