public class MysteryRadio : NetworkBehaviour, IInteractable
{
private bool isOn = false;
private Rigidbody rb;
private Transform currentHoldPoint;
[SerializeField] private float rotationSpeed = 0.5f;
private void Awake() => rb = GetComponent<Rigidbody>();
public string GetInteractableName() => "Old Radio";
public List<InteractionOption> GetOptions(GameObject player)
{
return new List<InteractionOption>
{
new() { Id = "power", DisplayName = isOn ? "Turn Off" : "Turn On", RequiresHold = false },
new() { Id = "drag", DisplayName = "Carry (hold E • right-click rotate)", RequiresHold = true, HoldDuration = 0f }
};
}
public void OnInteract(GameObject player, string optionId, InteractionPacket packet)
{
if (optionId == "power" && packet.ActionTag == "OnPress")
{
isOn = !isOn;
// → change emissive, play static sound, etc.
return;
}
if (optionId != "drag") return;
switch (packet.ActionTag)
{
case "OnHoldStart":
currentHoldPoint = player.GetComponent<PlayerInteraction>().holdPoint;
rb.useGravity = false;
rb.isKinematic = true;
break;
case "OnHoldUpdate":
// Rotate only when right-click is held
if (packet.Inputs.Any(x => x.KeyName == "CustomI_MouseRightClick"))
{
var mouse = packet.Inputs.Find(x => x.KeyName == "CustomI_MouseVector2");
if (mouse.KeyName != null)
{
Vector2 delta = mouse.VectorValue;
transform.Rotate(Vector3.up, -delta.x * rotationSpeed, Space.World);
transform.Rotate(Vector3.right, delta.y * rotationSpeed, Space.World);
}
}
// Throw when special key pressed
if (packet.Inputs.Any(i => i.KeyName == "CustomI_Deneme"))
{
currentHoldPoint = null;
rb.useGravity = true;
rb.isKinematic = false;
rb.AddForce(player.transform.forward * 500f);
player.GetComponent<PlayerInteraction>().BreakInteractionFromObject();
}
break;
case "OnHoldReleased":
case "OnHoldCanceled":
currentHoldPoint = null;
rb.useGravity = true;
rb.isKinematic = false;
break;
}
}
}