I’m trying to get simple touch input to work in MR bounded volume by making a simple 3D button script. It has a Box Collider and a script that checks for activeTouches during update. The code works in editor but not in XCode simulator. It seems like activeTouches.Count is always 0 in the XCode simulator. I use the same code in another part of the app also with a Box Collider and it seems to work and I’m feeling lost what the issue could be.
This is the script that I’m attaching.
using UnityEngine;
using UnityEngine.Events;
using Unity.PolySpatial.InputDevices;
using UnityEngine.InputSystem.EnhancedTouch;
using UnityEngine.InputSystem.LowLevel;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
using TouchPhase = UnityEngine.InputSystem.TouchPhase;
public class PolySpatialButton : MonoBehaviour {
public UnityEvent onClick;
private void Update()
{
var activeTouches = Touch.activeTouches;
Debug.Log ("Update " + activeTouches.Count);
if (activeTouches.Count > 0)
{
var primaryTouchData = EnhancedSpatialPointerSupport.GetPointerState(activeTouches[0]);
var interactionKind = primaryTouchData.Kind;
var objectBeingInteractedWith = primaryTouchData.targetObject;
var interactionPosition = primaryTouchData.interactionPosition;
Debug.Log ("Touch for" + objectBeingInteractedWith.transform.name);
if (activeTouches[0].phase == TouchPhase.Began && objectBeingInteractedWith == gameObject)
{
Debug.Log("Executing PolySpatialButton Action for" + objectBeingInteractedWith.transform.name);
var polySpatialButton = objectBeingInteractedWith.GetComponent<PolySpatialButton>();
if (polySpatialButton.onClick != null)
{
polySpatialButton.onClick.Invoke();
}
}
}
}
}