So I am going to write a script that allows to show some text when you click on a chest, Should I use an OnMouseDown
or OnCollisionEnter
? in which case, I would want to find the collision of the chest when you click on it. Thanks!
Asked
Active
Viewed 115 times
-2

Benzara Tahar
- 2,058
- 1
- 17
- 21

Sprky12
- 1
- 1
-
1Does this answer your question? [How to detect click/touch events on UI and GameObjects](https://stackoverflow.com/a/41392130/1092820) – Ruzihm Feb 17 '21 at 23:19
-
1Does this answer your question? [Unity - Add call back to GameObject OnMouseDown Event](https://stackoverflow.com/questions/35352225/unity-add-call-back-to-gameobject-onmousedown-event) – nkazz Feb 17 '21 at 23:21
-
Yes thanks :) the correct answer would be OnMouseDown. – Sprky12 Feb 17 '21 at 23:27
-
@Sprky12 Actually, `OnPointerDown` would be better, since it works with more than just mouse input, which includes being more performant for mobile, and allows you to have finer control over what blocks or does not block the click. See [How to detect click/touch events on UI and GameObjects](https://stackoverflow.com/a/41392130/1092820) – Ruzihm Feb 17 '21 at 23:31
1 Answers
0
OnCollisionEnter don't make any sense in this context. Just use OnMouseDown and show a UI text object. Add anytype collider to the chest and check IsTrigger Property of chest(If your game dont need to interact wit it physically). Then add component with OnMouseDown function and use necessary script to show UI Text object.

SeLeCtRa
- 600
- 1
- 6
- 14