Forum Discussion
VTDA
2 years agoExplorer
OnPointerExit & OnPointerEnter events unexpectedly fire after pressing & releasing the trigger
I have a simple script that plays an audio clip when the OnPointerEnter event fires and stops when the OnPointerExit event is fired If I hover over and then off of a UI element, like a toggle or bu...
VTDA
1 year agoExplorer
This is what I did in lieu of an official fix by Meta to satisfy my specific use case (to predictably play audio on hover events):
using UnityEngine;
using Oculus.Interaction;
public class PlayAudioOnHoverMETA : MonoBehaviour
{
[SerializeField] private AudioSource audioSource;
private bool isPointerOver = false;
void Start()
{
PointableCanvasModule.WhenSelectableHovered += OnSelectableHovered;
PointableCanvasModule.WhenSelectableUnhovered += OnSelectableUnhovered;
}
void OnDestroy()
{
PointableCanvasModule.WhenSelectableHovered -= OnSelectableHovered;
PointableCanvasModule.WhenSelectableUnhovered -= OnSelectableUnhovered;
}
private void OnSelectableHovered(PointableCanvasEventArgs args)
{
if (args.Hovered == this.gameObject && audioSource != null && !audioSource.isPlaying && !isPointerOver)
{
audioSource.Play();
isPointerOver = true;
//Debug.Log("Play Audio Clip on Enter\n");
}
}
private void OnSelectableUnhovered(PointableCanvasEventArgs args)
{
if (audioSource != null)
{
audioSource.Stop();
isPointerOver = false;
//Debug.Log("Stop Audio Clip on Exit\n");
}
}
}Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 years ago
- 9 years ago