mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-23 07:38:33 -05:00
43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
public class HoverOutline : MonoBehaviour
|
|
{
|
|
private Outline outline;
|
|
private XRGrabInteractable grabInteractable;
|
|
private void Start()
|
|
{
|
|
// Get the Outline component attached to the object
|
|
outline = GetComponent<Outline>();
|
|
if (outline == null)
|
|
{
|
|
Debug.LogError("Outline component not found on the object.");
|
|
return;
|
|
}
|
|
|
|
// Get the XRGrabInteractable component attached to the object
|
|
grabInteractable = GetComponent<XRGrabInteractable>();
|
|
if (grabInteractable == null)
|
|
{
|
|
Debug.LogError("XRGrabInteractable component not found on the object.");
|
|
return;
|
|
}
|
|
// Subscribe to the hover events of the XRGrabInteractable
|
|
grabInteractable.onHoverEntered.AddListener(OnHoverEnter);
|
|
grabInteractable.onHoverExited.AddListener(OnHoverExit);
|
|
|
|
// Initially, disable the outline
|
|
outline.enabled = false;
|
|
}
|
|
|
|
private void OnHoverEnter(XRBaseInteractor interactor)
|
|
{
|
|
// Enable the outline when hovering over the object
|
|
outline.enabled = true;
|
|
}
|
|
|
|
private void OnHoverExit(XRBaseInteractor interactor)
|
|
{
|
|
// Disable the outline when the hover ends
|
|
outline.enabled = false;
|
|
}
|
|
} |