1
NGUI 3 Support / Physics.RaycastAll keeps hitting "UI Root" and nothing else
« on: May 15, 2016, 10:55:33 PM »
No matter what I do, I keep running into this problem when raycasting with the uicamera on a separate layer. I have Event Type set to 3D UI, in physics settings I have "Queries Hit Triggers" turned on as was suggested by someone who had a similar problem in a different thread. Still though, I can never get anything returned by UI Root.
The only way I've been able to raycast beyond UI Root is by removing the Rigidbody from UI Root, however, removing rigidbody is not a permanent fix as it is required and the UI Root just adds it back every time the scene starts anyway.
Here's the code:
Any suggestions? I'm trying to raycast to a non NGUI model that is being displayed on the UI.
Thanks.
The only way I've been able to raycast beyond UI Root is by removing the Rigidbody from UI Root, however, removing rigidbody is not a permanent fix as it is required and the UI Root just adds it back every time the scene starts anyway.
Here's the code:
- void Update()
- {
- Ray ray = uiCamera.ScreenPointToRay (Input.mousePosition);
- Debug.DrawLine (uiCamera.ScreenPointToRay(Input.mousePosition).GetPoint(0f), uiCamera.ScreenPointToRay(Input.mousePosition).GetPoint(0f)+Vector3.forward*100f,Color.red, 1000f);
- RaycastHit[] hit;
- hit = Physics.RaycastAll (ray, 400f);
- for (int i = 0; i < hit.Length; i++)
- {
- Debug.Log ("Hit " + hit[i].transform.gameObject.name);
- if (hit [i].transform.gameObject.layer == 8)
- {
- selectedModel = hit[i].transform.gameObject.name;
- InstantiateSelectedModelInUI (selectedModel);
- }
- }
- }
Any suggestions? I'm trying to raycast to a non NGUI model that is being displayed on the UI.
Thanks.




