Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: tnbao91original on September 07, 2014, 09:27:06 PM

Title: Best way for raycast only UI
Post by: tnbao91original on September 07, 2014, 09:27:06 PM
My issue is raycast when i touch UI this make raycast twice for UI and screen but i only wanna make UI touch. May someone show me how to solve this ?
Title: Re: Best way for raycast only UI
Post by: tnbao91original on September 07, 2014, 10:36:07 PM
I used UICamera.hoverObject != null and work fine but only PopupList with dropdown list this not work when i touch item in dropdown list. So when i press an UI and drag it, i wanna stop raycast in gameplay scene too but i cant.
Title: Re: Best way for raycast only UI
Post by: tnbao91original on September 08, 2014, 03:44:51 AM
Another issue is mobile plaform which not has hover state, my first solution totally fail :3
Title: Re: Best way for raycast only UI
Post by: ArenMook on September 08, 2014, 08:52:33 PM
I don't quite understand you here... raycast twice for UI and screen? What does "make UI touch" mean?

UICamera is what controls which cameras receive events. If you remove this script from a camera, objects that are drawn by that camera won't be receiving events. If you only have UICamera on the camera that draws your UI, then only UI elements will receive events.
Title: Re: Best way for raycast only UI
Post by: tnbao91original on September 09, 2014, 11:47:10 AM
Sorry for my bad English, I have 1 button and character 3d model behind it. Character will move if i touch on screen and it make me crazy when i touch button ngui and character move too. But i solved my problems by this code in UICamera

  1. Ray ray = UICamera.currentCamera.ScreenPointToRay(m_vTargetPos);
  2.             RaycastHit currentTouchorMouse;
  3.             Physics.Raycast(ray, out currentTouchorMouse, 1000);
  4.  
  5.                 if (currentTouchorMouse.collider.gameObject.layer == LayerMask.NameToLayer("UI"))
  6.                 {
  7.                     return;
  8.                 }

Thank you for reply me :)
Title: Re: Best way for raycast only UI
Post by: ArenMook on September 10, 2014, 12:54:14 AM
Don't modify the UICamera.

Change the Event Mask on the UICamera instead.

Also make sure that your Main Camera doesn't draw your UI layer, and that your UI camera doesn't draw your 3D layers.
Title: Re: Best way for raycast only UI
Post by: tnbao91original on September 10, 2014, 09:39:20 AM
Ya I just copy a part code of UICamera in Raycast method and use it for dectected what object selected. May u think Raycast method in UICamera should be return a gameobject ?