- Home /
GraphicRaycaster not detecting UI elements
Hi everybody,
This is my first time working with the GraphicRaycaster and I seem to have been running into an issue. I'm making a kinect game where I want player's hand to interact with UI elements. For this I attached gameobjects to the player's hand that should fire rays to the canvas. My code is as follows:
private GraphicRaycaster myRaycaster;
private PointerEventData ped;
private List<RaycastResult> rayResults;
public void Start()
{
// I'm using the same raycaster in the canvas
myRaycaster = UISingleton.Instance.GetComponent<GraphicRaycaster>();
ped = new PointerEventData(null);
rayResults = new List<RaycastResult>();
}
void Update () {
ped.position = Camera.main.WorldToViewportPoint(this.transform.position);
myRaycaster.Raycast(ped, rayResults);
Debug.Log("we have hit " + rayResults.Count + " objects");
}
The canvas has only one element (a button), and this is an empty scene otherwise. However I always get 0 hit results off of the raycaster. It just doesn't seem to detect it. Any ideas on what this could be?
Thanks!
Your answer
Follow this Question
Related Questions
Help with Raycast on Render Texture 0 Answers
Canvas Disabled but UI elements still block Raycasts 4 Answers
UI Buttons visible but not clickable when using two canvases. 3 Answers
Interacting with images on the canvas 0 Answers
How to get PointerEventDatas[]? 0 Answers