- Home /
Determining which collider attached to same object was clicked
I have a particular GameObject with a texture of a number of buttons set in a particular order.
I want the user to be able to click on any of those buttons, and something different to happen depending on which button was clicked.
I put a different circle collider around each one, and I'm expecting to handle it through "OnMouseUp" attached to the game object.
How can I determine which particular collider was clicked on? Should I be doing something else ?
Thanks
Answer by Kiwasi · Jun 05, 2014 at 09:15 PM
RaycastHit.Collider is probably your best bet here.
Right, and how do I use this exactly? I basically want a different piece of code to execute whenever I click on a different collider. Do I keep a reference to each collider in the script somehow to compare with this one?
Answer by pacific00 · Jun 06, 2014 at 06:43 AM
use guitexture for the buttons and hitTest( input.mousePosition ) to check for clicks on them
Your answer
Follow this Question
Related Questions
OnTriggerEnter and OnTriggerExit both trigger twice 0 Answers
C# Invalid Points Assigned to 2D Edge Collider 1 Answer
Unity2D - Box Collider 2D problem 0 Answers
Do 2d Colliders cause problems when inside nested objects in Unity? 0 Answers
GameObject ignores collision while swinging from hinge joint 2D 4 Answers