Mouse should Check Collison of object and change its color

Hello Guys,
I’ve been working on my game where i have 2 blocks and if i click one block with mouse that block should change its color but both blocks are changing their color.I have placed them in Default Layer and Also Added Collison both Mesh and Box. i also Tried With Mesh Collider Active and Box Collider Active Separately.But it Did not Work please Help.I code which i tried is:
void Update()
if (Input.GetMouseButtonDown(0))

It looks like you have not programmed all the conditionals you need:

You do check if the mouse button is down, but you do NOT check the location of the mouse.

You will need to either:
check the mouse location on click, and see if that is “on” one of your blocks (and if so, which one). Then you can highlight only that block.
(you’ll need this function- Unity - Scripting API: Camera.ScreenPointToRay, and some knowledge of raycasting: 3D Physics - Unity Learn)


setup a trigger on each block, that is automatically called by the unity event system on click. (you’ll need to learn about callbacks and event system stuff- I suspect this interface will be useful: Redirect to... title of new-page)