- Home /
Is It Possible to Detect a Collision Within a Canvas?
Hello all, for my game I have a canvas where the user can scroll through to select an item (using Scroll Rect). I have a collider in the center of the screen. The purpose of this collider is to detect which item is in the center of the screen (yes, the other images in the Scroll Rect has 2D colliders on them).
The goal is to display the name of the item that is in the center of the screen by detecting a collision with the collider (that is a trigger) in the middle of the screen, and the collider on the items that are being scrolled through. Here's a snippet of my code:
public void OnTriggerEnter2D (Collider2D other) {
Debug.Log ("New item in center of screen");
Text _text = GameObject.Find("Name").GetComponent<Text> ();
_text.text = other.gameObject.name;
}
As the code states, when an image that has a 2D collider on it enters the collider in the middle of the screen, the name of the item should be displayed. This is not happening.
Any help!?
Answer by AustinMeiron · Oct 13, 2016 at 09:44 PM
Solved! For whatever reason, the detecting collider needed a Rigidbody2d component.
Works great now! http://answers.unity3d.com/questions/592567/why-isnt-my-ontriggerenter2d-function-working.html
Answer by blabberbytes · Aug 22, 2020 at 08:44 AM
I cannot figure this out, can someone help a noob out!?
Your answer
![](https://koobas.hobune.stream/wayback/20220612094544im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to use different OnTriggerEnter2D function for 2 collider of a game object? 1 Answer
Checking if a single object's trigger is entered out of a group of identical objects? 1 Answer
Colliding two GameObjects 1 Answer
Can't figure out how to use multiple triggers in single scene 1 Answer
Array for multiple cameras? 2 Answers