http://blog.csdn.net/lyh916/article/details/50947026
1.Graphic Raycaster
Primarily for Ray detection on the UI, objects with this component must be hung on canvas (the canvas will automatically hang when graphic raycaster is hung).
Ignore reversed Graphics: whether to ignore the inverse direction of the graphic, if true, indicates that the graphic front of the display, will receive a ray detection, negative display, do not receive radiographic inspection; otherwise, the positive and negative display will receive a ray detection
Blocking Objects: Masks (physical) objects of the specified type so that they do not participate in Ray detection. Rendering mode does not work when screenspaceoverlay. The optional values are:
None: Do not block any physical objects
D: Block 2D physical objects (that is, objects with 2D collisions)
Three D: Masking 3D physical objects (i.e. objects with 3D collisions)
All: Block all Object objects
Blocking Mask: Causes the specified layer in the masked object not to participate in radiographic inspection. The rendering mode is not screenspaceoverlay, and blocking objects does not work when it is none.
For example, Blocking objects is a UI for 2d,blocking mask, meaning that anything in a 2D physical object that is in the UI layer will not receive ray detection, while the other layers in the 2D physical object will still be able to receive Ray detection
2.Physics Raycaster & physics2d Raycaster
It is mainly used for Ray detection on physical objects, and objects with this component must be hung onto the camera component (the camera will automatically hang when the component is attached). When an object (2D or 3D physical object) is detected by a ray, the method that implements the event interface on the object is called
Physics Raycaster: Only affects 3D object objects, camera projection, as far as possible to choose perspective (Perspective) mode
Physics2d Raycaster: Only affects 2D object objects, camera projection, as far as possible to choose orthography (orthogonal) mode
Eventmask: A ray-acting layer that can be used to do event masking
3.Selectable
Selectable means optional, it is the base class for many interactive controls (Button/slider/inputfield/toggle/scrollbar/) in Ugui, where interactable, when the value is false, The UI control enters the Disable state (the color becomes the color of disabled color), but the UI control can still receive the ray detection!
4.CanvasGroup
Used to manage the control in bulk and the UI controls under the control. Interactable The meaning above has been said, and blocks raycasts, if False, the UI control can not receive Ray detection
Ray penetration:
For example, button and image both implement the Click interface, if you want to click on the overlap between the two, the button event is not triggered, and the event of the image is triggered, the method is:
Attach the canvas group component to the button and uncheck blocks raycasts
5. Determine if the mouse or finger is clicked on the UI
For EventSystem.current.IsPointerOverGameObject this function, because EventSystem is the UI's event system, Gameobject in Ispointerovergameobject is for the UI, not the Universal Gameobject in the sense of
[CSharp]View PlainCopy
- Using Unityengine;
- Using Unityengine.ui;
- Using Unityengine.eventsystems;
- Public class Testtouch:monobehaviour {
- public text text;
- void Update ()
- {
- if (input.getmousebuttondown (0) | | (Input.touchcount > 0 && input.gettouch (0). Phase = = Touchphase.began))
- {
- #if Unity_android | | Unity_iphone
- if (EventSystem.current.IsPointerOverGameObject (Input.gettouch (0). Fingerid))
- #else
- if (EventSystem.current.IsPointerOverGameObject ())
- #endif
- Text.text = "Current touch on UI";
- Else
- Text.text = "There is currently no touch on the UI";
- }
- }
- }
"Go" [Unityui]ugui-ray detection