75 lines
1.7 KiB
C#
75 lines
1.7 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
using VRC.Udon.Common.Interfaces;
|
|
|
|
|
|
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
|
|
public class JailChain : UdonSharpBehaviour
|
|
{
|
|
[SerializeField] private GameManagerRound2 _GameManager;
|
|
[Space]
|
|
[SerializeField] private Transform _ChainPivot;
|
|
[SerializeField] private Transform _RingPivot;
|
|
[SerializeField] private Transform _RingGrabberHome;
|
|
[SerializeField] private Transform _PullTarget;
|
|
[Space]
|
|
[Tooltip("Speed at which the chain returns to its neutral pose.")]
|
|
[SerializeField] private float _ReturnSpeedMultiplier = 5.0f;
|
|
|
|
private bool _PullChain = false;
|
|
private bool _HasBeenActivated = false;
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (_PullChain)
|
|
{
|
|
_RingPivot.transform.position = transform.position;
|
|
_ChainPivot.LookAt(transform);
|
|
|
|
if (!_HasBeenActivated && transform.localPosition.z < _PullTarget.transform.localPosition.z)
|
|
{
|
|
_HasBeenActivated = true;
|
|
if (Networking.IsOwner(gameObject))
|
|
{
|
|
_GameManager.SendCustomNetworkEvent(NetworkEventTarget.All, "PlayInJailAnimation");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
transform.localPosition = Vector3.Lerp(transform.localPosition, Vector3.zero, Time.deltaTime * _ReturnSpeedMultiplier);
|
|
_RingPivot.transform.position = transform.position;
|
|
_ChainPivot.LookAt(transform);
|
|
}
|
|
}
|
|
|
|
public override void OnPickup()
|
|
{
|
|
_PullChain = true;
|
|
RequestSerialization();
|
|
base.OnPickup();
|
|
}
|
|
|
|
public override void OnDrop()
|
|
{
|
|
_PullChain = false;
|
|
RequestSerialization();
|
|
base.OnDrop();
|
|
}
|
|
|
|
|
|
public void Initialise()
|
|
{
|
|
_PullChain = false;
|
|
_HasBeenActivated = false;
|
|
|
|
transform.localPosition = Vector3.zero;
|
|
_RingPivot.transform.position = transform.position;
|
|
_ChainPivot.localRotation = Quaternion.identity;
|
|
}
|
|
}
|