Reputation: 115
I need to get the coordinates of the collision between the gaze pointer and an objects in Hololens, when the object is "clicked".
All the examples use MRTK1, how do you do this in MRTK2? I know you need to use the cursor, but how do you get it= It only appears when I actually run the code.
This is what I have so far:
using Microsoft.MixedReality.Toolkit.Input;
public class MoveTo : BaseInputHandler, IMixedRealityInputHandler
{
public GameObject Sphere;
public GameObject Cursor;
public void OnInputUp(InputEventData eventData)
{
GetComponent<MeshRenderer>().material.color = Color.red;
}
public void OnInputDown(InputEventData eventData)
{
Vector3 gazePos = Cursor.transform.position;
Sphere.transform.position = gazePos;
GetComponent<MeshRenderer>().material.color = Color.green;
}
}
Upvotes: 1
Views: 524
Reputation: 115
Figured it out. I had to use the pointer handler instead. This code works:
public class MoveTo : BaseInputHandler, IMixedRealityPointerHandler
{
public GameObject Sphere;
public void OnPointerDown(MixedRealityPointerEventData eventData)
{
GetComponent<MeshRenderer>().material.color = Color.green;
}
public void OnPointerDragged(MixedRealityPointerEventData eventData)
{
}
public void OnPointerUp(MixedRealityPointerEventData eventData)
{
Vector3 gazePos = Sphere.transform.position;
Sphere.transform.position = eventData.Pointer.Result.Details.Point;
GetComponent<MeshRenderer>().material.color = Color.red;
}
public void OnPointerClicked(MixedRealityPointerEventData eventData)
{
}
}
Upvotes: 1