Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 866 Bytes

UIRayDetect.md

File metadata and controls

20 lines (18 loc) · 866 Bytes

Technical Summary

To detect whether the mouse overlaps with an object on the screen, it is not necessary to obtain the screen coordinates and borders of the object to perform complex calculations. Unity provides us with ray detection and also provides a way to convert mouse coordinates into rays.

Sample Code

// Camera.main.ScreenPointToRay(Input.mousePosition): Convert mouse coordinates to rays
// Physics.Raycast: X-ray Detection
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
{
    if (target_name == hit.collider.name)
    {
        // Do Something...
    }
}

Related Documents