- Home /
Detect if UI Image is in a trigger
Hello,
I was making my game, but i ran into this problem... I dont know how to detect two UI images, if one is in the trigger of the other image. Can somebody tell me exactly how can i do it?
They are rectangular. You could just check if their bounds overlap? You'd add Rigidbodies to them and move those otherwise.
Can you write exactly what I need to do? :) This is the first time when I am working with UI and I dont really know what you wrote here.
Answer by awaismazhar999 · Jun 16, 2017 at 05:51 AM
Dear @username, For detecting the trigger on UI gameObject, You need to do the following:-
Attach colliders2D to both of the game Object and make sure that one of them is triggered check.
Attach Rigidbody2D to them.
Assign Tag one gameObject i.e. "Mytag"
Attach the script to other UI gameObject having this code :-
void OnTriggerEnter2D(Collider2D other) { if(other.gameObject.tag=="Mytag") { //Do whatever you want to do } }
Follow this Question
Related Questions
How to trigger OnValueChange(Vector 2) method from code? 1 Answer
Add Listeners to array of Buttons 2 Answers
Image as boundary 1 Answer
Only Rotate UI HUD on orientation change. 0 Answers
Space Shooter Tutorial 5.3 first Asteroid being destroyed 0 Answers