- Home /
Check if an image has been clicked
If this has been asked before and answered please point me to it.
I want so that when someone clicks an image, things happen. I want it to require a right click and only happen when you click on that one image. No rects because I cant get them to work.
Thanks!
are you asking if a GUI texture has been clicked or a game object has been clicked? 2d or 3d? this could be two entirely different questions.
what are you doing?
Answer by aklgupta · Apr 21, 2017 at 09:35 AM
I am not 100% certain what is it that you require, but I'll go with what i understood. If that image is a part of the UI/canvas, you can make it a button instead.
If it is a sprite, then add a Box Collider 2D
to it, and attach a script with the follwoing function OnMouseUpAsButton()
eg.
private void OnMouseUpAsButton() { %|-524112790_1|% }
You can also use OnMouseUp()
but I prefer OnMouseUpAsButton()
You can read more about the function here https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseUpAsButton.html
or see more similar functions here, under the Messages heading https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
Is there a way to do this externally, like from another object.
Thanks!
Well, it depends on what method you use, and what you want to do. There are many method to achieve what you want, or maybe none. I can't quite answer that without knowing what is it that you want. I'd suggest asking a new question, that way others more experienced than myself can also help you out.