I'm detecting mouse clicks if the click is happening over the collider but I don't want to fire mouse clicks if it is on the trigger object. How to I do this? Any suggestions?

  • \$\begingroup\$ How are you detecting which object was clicked? \$\endgroup\$
    – SanSolo
    Nov 18, 2015 at 4:46
  • \$\begingroup\$ I'm using OnTriggerStay2D() method and some boolean variables to detect the mouse click... void OnTriggerStay2D (Collider2D col) { if (gameObject.name == "elephant" && col.gameObject.name == "elephant 1") { canShow = true; if (canClick) { Show (col.gameObject); ObjectActivate ("book1"); } } canClick will become true if the object on the trigger and the mouse is clicked. But i don't want user to click on the trigger object. \$\endgroup\$ Nov 18, 2015 at 4:59
  • \$\begingroup\$ Where is this Collision detection script attached? \$\endgroup\$
    – SanSolo
    Nov 18, 2015 at 5:29
  • \$\begingroup\$ Gameobject that i am picking. Here it is 'elephant'. \$\endgroup\$ Nov 18, 2015 at 5:30
  • 1
    \$\begingroup\$ Ok. How are you detecting Mouse clicks? \$\endgroup\$
    – SanSolo
    Nov 18, 2015 at 5:37

1 Answer 1


How to detect clicks on object? . This is a question I had asked. The proper way to detect mouse clicks is to use RayCasting, RayCast2D for 2D. While Raycasting, you can specify layermask, which let's you ignore objects which you want to ignore.

The second answer on the aforementioned question provides a solution for 2D.

  • \$\begingroup\$ Yeah it's good but how do i detect collision when the object collid with another object. Because here we can't use default OnTriggerXXX() method.... \$\endgroup\$ Nov 18, 2015 at 5:33
  • \$\begingroup\$ Your question is not clear. In your post, you asked : "I'm detecting the mouse clicks" . This answers how to detect mouse clicks. If you want to know how to detect collision between two objects, post a new question. \$\endgroup\$
    – SanSolo
    Nov 18, 2015 at 5:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .