Unity Two Method of Interacting Objects with Mouse

OnMouseDown()

This is one of the easiest script to write for a game object. All you need to do write the interaction code in the function OnMouseDown() and attach it to the game object.

Raycast

Unity ray cast can also do the trick, first make three variable, the Ray, the objects it hits, and lastly to store the Target of your choice. Inside the Update function, if we left click, we get a list of all the target hits, for then we check for tags. For each game object that has the tag target, we know we got the object and then we can do anything we want with it.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store