- Home /
Detect which object is clicked with RayCast
Hello,
I have a (hopefully) small problem with the RayCast. I bought a highlighter from the Unity store, and it works fine. Whenever I click an object with the Highlighter script attached to it, it lights up, as well as any other object.
Now, the thing I'd need is the additional code which will detect which object I clicked, and detect when I deselected it. I need this because I'm testing a scene with 3 objects on it. Clicking on each highlights it, and only when ALL 3 are selected, something should happen. Also, third is unclickable until the first and second are highlighted. I'm guessing that this needs to be done with RayCast as well, I just need help on how to detect which and how many objects are selected.
Any ideas/help on how to do it?
Thank you in advance for your replies!
Something like:
GO1 - On$$anonymous$$ouseDown 1wasClicked = true
GO2 - On$$anonymous$$ouseDown 2wasClicked = true
GO3 - On$$anonymous$$ouseDown if 1wasClicked && 2wasClicked do stuff
Answer by archie_azares · Sep 01, 2013 at 06:40 AM
try using RayCastHit and compare it using if else statement
Your answer
![](https://koobas.hobune.stream/wayback/20220613113347im_/https://answers.unity.com/themes/thub/images/avi.jpg)