- Home /
How to detect when an object goes past (so it looks like it touches) a UI element.
I have a UI element in the top right of my screen. When the player collects coins they shoot up in to the top right of the screen and past the UI element. I want to be able to detect when it goes past the element.
I considered adding a box collider top the UI element and using collision/trigger, the issue os that the canvas in engine is actually off screen the rendered over the camera so the box collider isnt actually where it looks like it is.
I also tried using if(object is at position), but because the positions go in to the .0000000's, it was very rarely hitting it.
Are you wanting actual collisions with UI objects and game objects, so that physics/layers evoke collisions? Or, do you just need to know if an object passes through the coordinate area of a UI object?
I just need to know if its passed through so I can then delete the game object and play an animation that makes it look like the coin has gone in to the UI element.
Answer by B3Designs · Oct 18, 2020 at 04:06 PM
Personally I'd convert the coin's position from World to Screen coordinates, then just check for proximity to your UI element, assuming the UI never moves of course...
A lot quicker and easier than try to do it through collisions.
Your answer
Follow this Question
Related Questions
Create hinge joint 2D by collision 2 Answers
Want to detect if object is in grid. 1 Answer
3D Objects on a UI canvas with LWRP? 2 Answers
Radial Progress Bar AOE 1 Answer