- Home /
How to select an ui image with mouse click and touch?
I have selected ui>image and I want to select that image with mouse click and touch
i also added a script with that image obj:
// It works fine while start function Start(){ Debug.Log(gameObject.name); }
// It's not working function OnMouseDown(){ Debug.Log(gameObject.name);
}
no collider or mesh randerer or rigid body attached just a script is attached
Answer by Hellium · Jun 18, 2015 at 07:01 AM
You will have to deal with Events triggers if you want to keep the Image script only. By the way, I don't think it's a good practice to add a button script + Image this way (since the button can already display an image)
See tutorial on events triggers : https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-events-and-event-triggers
Otherwise, you could only keep the button script and put the target graphic as you did. In that case, you can just :
Click on the "+" button under the "On Click" panel of the button script
Put the object where the desired function must be called
Select the script + function to call when a click is detected on your button
@agosaravanan P Did it help ? Please, don't forget to feedback, others can face the same problem ! ;)
Thnx bro for ur ans. I just used event trigger method(pointer click) and added a script(myfunction) with that image obj now it works fine while I click on that obj.
Your answer

Follow this Question
Related Questions
Cannot get Image-based Touch Controller to Work 0 Answers
Check if an image has been clicked 1 Answer
Make touch buttons transparent 2 Answers
UI Image and OnMouseDown not working 3 Answers
Touch and Swipe at the same time mobile 0 Answers