Summary I wrote a simple Class (InteractableObject) to help highlight when my hand is interacting with an object. What is a performant and Idiomatic way to script this interaction?
I'm using the latest version 63 of both "meta all in one sdk" and Interaction SDK"
https://assetstore.unity.com/packages/tools/integration/meta-xr-all-in-one-sdk-269657 https://assetstore.unity.com/packages/tools/integration/meta-xr-interaction-sdk-264559
Here is some loose pseudocode to help describe what I"m trying to do.
using UnityEngine;
public class InteractableObject : MonoBehaviour
{
public bool highlightOnHover = true; // Should the object change appearance when hovered over?
public Material highlightMaterial; // Material to use for highlighting
private Renderer myRenderer; // Stores a reference to our renderer
private Material originalMaterial; // Stores the object's original material
void Start()
{
myRenderer = GetComponent<Renderer>();
originalMaterial = myRenderer.material;
}
// Replace with the actual Interactor component type
void OnCollisionEnter(Collision collision)
{
OVRInteractor interactor = collision.collider.GetComponent<OVRInteractor>();
if (interactor != null)
{
HandleInteraction();
}
}
// Replace with the actual Interactor component type
void OnCollisionExit(Collision collision)
{
OVRInteractor interactor = collision.collider.GetComponent<OVRInteractor>();
if (interactor != null)
{
HandleInteractionEnd();
}
}
void HandleInteraction()
{
Debug.Log("Interactable object collided with OVR hand!");
if (highlightOnHover)
{
myRenderer.material = highlightMaterial;
}
// ... Add your custom interaction logic here ...
// Play sounds, trigger events, etc.
}
void HandleInteractionEnd()
{
if (highlightOnHover)
{
myRenderer.material = originalMaterial;
}
}
}