71 lines
1.3 KiB
C#
71 lines
1.3 KiB
C#
|
|
using UdonSharp;
|
|
using UnityEngine;
|
|
using UnityEngine.Animations;
|
|
using VRC.SDK3.ClientSim;
|
|
using VRC.SDKBase;
|
|
using VRC.Udon;
|
|
|
|
public class Horseshoe : UdonSharpBehaviour
|
|
{
|
|
private bool IsBeingHeld = false;
|
|
[UdonSynced, FieldChangeCallback(nameof(SetIsInHome))]
|
|
private bool IsInHome = true;
|
|
|
|
private ParentConstraint HorseshoeConstraint;
|
|
private Rigidbody HorseshoeRigidBody;
|
|
|
|
|
|
public void Start()
|
|
{
|
|
HorseshoeConstraint = GetComponent<ParentConstraint>();
|
|
HorseshoeRigidBody = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
public override void OnPickup()
|
|
{
|
|
IsBeingHeld = true;
|
|
EnableConstraints(false);
|
|
|
|
base.OnPickup();
|
|
}
|
|
|
|
public override void OnDrop()
|
|
{
|
|
IsBeingHeld = false;
|
|
|
|
if (IsInHome)
|
|
{
|
|
EnableConstraints(true);
|
|
}
|
|
else
|
|
{
|
|
EnableConstraints(false);
|
|
}
|
|
|
|
base.OnDrop();
|
|
}
|
|
|
|
|
|
private void EnableConstraints(bool enable)
|
|
{
|
|
HorseshoeRigidBody.useGravity = !enable;
|
|
HorseshoeConstraint.enabled = enable;
|
|
}
|
|
|
|
public bool SetIsInHome
|
|
{
|
|
set
|
|
{
|
|
IsInHome = value;
|
|
|
|
if (!IsBeingHeld && IsInHome)
|
|
{
|
|
EnableConstraints(true);
|
|
}
|
|
}
|
|
|
|
get => IsInHome;
|
|
}
|
|
}
|