Raycasters

Remember that the Event System keeps track of Raycasting along with all the other things we have discussed. Raycasting is used to determine which UI elements are being interacted with by projecting a ray from the user's pointer into the scene. This ray is considered to originate at the camera's plane and then proceed forward through the scene. Whatever this ray hits, receives an interaction. You can have the ray continue on through the first UI element it hits or stop at the first UI element hits. To get a ray to stop at the first UI element it hits, the object must block raycasting. This will stop items behind it from being interacted with.

Get Mastering UI Development with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.