- Home /
Duplicate Question
C# GetMouseButtonUP on specific object ???
How to Click a specific object ?
What I know is Input.GetMouseButtonUp. But when I click on any object or any where, it always become activated.
It should not be like this.
What I want to do is when I click the specific object, then it will become activated....
Any idea how to make it work only on the specific object ?
Here is my script in update section :
if (Input.GetMouseButtonUp(0)) {
if (imode == 0) { imode=1; } else { imode=0; }
}
if (imode == 1) {
print ("The object is clicked");
}
PS : imode is an integer.
How to use the On$$anonymous$$ouseUp ? Can you give me the detailed solution ?
if my question is a duplicated one, then can you tell me which link ask the same question as $$anonymous$$e ?
Take the code I posted in my comment, put it an otherwise empty C# class, and attach it to your object (must have a collider). Each time the mouse goes up over the object the script is attached to, the On$$anonymous$$ouseUp() function will be called. There is also an On$$anonymous$$ouseDown() the the reference $$anonymous$$onoBehaviour reference page for the other On$$anonymous$$ouse* callbacks. Note it works with touch as well.
http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseUp.html
IC it based on $$anonymous$$onoBehaviour.
BTW you mentioned that "it works with touch as well"...
Does it mean I can use the On$$anonymous$$ousexxx on a device with touch screen capability ?