Is there a way to ignore OnMouseDown() if a collider is set to Trigger mode?
Hey there, so I'm making a tower defence game and using a circle collider set to "is trigger" to detect which enemies are in the range of a certain tower, but because of that if I click anywhere in the range of the tower it calls OnMouseDown(), I would like it to only be called when the mouse is over the sprite instead.
Is there a way to ignore that specific collider when clicking? The only other work around I can think of is to rewrite the detection system using the OverlapSphere function.
Thanks so much for your time!
Answer by tormentoarmagedoom · May 10, 2019 at 10:47 AM
HEllo.
To have better control of what players click on, is recommended to use Raycasting . This way you can detect all colliders in a straight line from the mouseclick, and then using if sentences can specify what to click.
I recommend you to watch this 2 tutorials:
https://www.youtube.com/watch?v=EINgIoTG8D4
https://www.youtube.com/watch?v=Hbo7vmsrABU
Bye!
Your answer

Follow this Question
Related Questions
Trigger Collinder doesnt work with Input.GetKey 1 Answer
OnMouseDown not working under Character Conroller 0 Answers
Bridge Paradox @ 2D Collider Problem 0 Answers
Touchscreen Start Button 2 Answers
Do I need Rigid2DBody if I don't plan to use physics? 2 Answers