Use OnMouseOver function and get the collider info of the object the mouse is over

How can I get the collider of the object’s transform the mouse is over by using OnMouseOver function

3 ways:

  1. If you have your own script on the game object also having a collider, you just add an OnMouseOver function to that script. It will be called when mouse is over the collider and you get the collider with GetComponent on the game object.

  2. Or you can create a specific script that just does above.

  3. You can instead ray cast every frame and find the component that the ray hits (see here).