Is there a way to test the collision of two gameObjects

right now i’m trying to find a way to test two different game objects. I want it so if it hits the gameObject called top it sets the variable t to true or if it hits the gameObject bottom it sets the variable to false. torb means top or bottom.

function OnCollisionEnter2D(torb : Collision2D){
	if (torb.gameObject.tag == top)
	{
		t = true;
	}
	else if (torb.gameObject.tag == bottom)
	{
		t = false;
	}

Both objects should have a collider2d (of some kind) and at least one should have a rigidbody2D attached.

Also, I’m not familiar with JavaScript, but given that t is having it’s true and false values used to signal top/bottom, how are you handling the case if torb has neither tag assigned?

1.Set up the colliders in all three objects (make sure is trigger is not checked)…
2.either add rigidbody/rigidbody2d to the moving object or to the other two object… If u r not using physics turn them to kinematics.
3.make sure u have the tags properly assigned to the top and bottom object in the inspector. create tags as necessary and then add them after u create. (creating only dont add automatically to the game object)
4.if u dont want to use tags u could just do like. make sure the names are same as in the hierarchy(but i would rather use tags)

 function OnCollisionEnter2D(torb : Collision2D){
     if (torb.transform.name == "name of top obeject")
     {
         t = true;
     }
     else if (torb.transform.name == "name of bottom obeject")
     {
         t = false;
     }
}