How to detect when two gameObjects collide by name {java, 2d}

I’ve got a box & piece of terrain called “Area1grass”. The box has a 2d box collider & the terrain has a 2d polygon collider. Both colliders are set to be triggers.
This script below moves the box left & right using the arrow keys, it moves down automatically 0.019 & is supposed to move up by 0.02 when it collides with the terrain {it warps back to the top if it goes too far down}. It’s just a simple test to become familiar with colliders:

#pragma strict


function Start () {
	
}

function Update () {
	if(Input.GetKey ("left")){
	transform.position.x = transform.position.x -0.1;
} if(Input.GetKey ("right")){
		transform.position.x = transform.position.x + 0.1;
		}
transform.position.y = transform.position.y - 0.019;
if(transform.position.y < (-5)){
	transform.position.y = 6;
	}
}

function OnCollisionEnter(collider : Collider){
	if(collider.gameObject.tag == "Area1grass"){
		transform.position.y = transform.position.y + 0.02;
	}
}

Everything else is running just fine except that the box falls through the terrain every time, I’ve been through countless questions/answers on here & none of them seem to work >.>
Remember I’m not using rigidbodies or Unity’s built in physics; I simply want to know how to detect when one gameObject is touching another.
Any help is much appreciated ^-^

You’re close.

Put your collision logic in OnTriggerEnter2D instead.

There are several points to keep in mind when you want to detect collisions.

  1. What Kind of Collider you are using? One of the 2D Colliders or 3D Colliders. If you are using 2D Collider, you can use methods like OnCollisionEnter2D or OnTriggerEnter2D only.
  2. Whether IsTrigger is checked on the Collider? IsTrigger specifies that an object can pass through a colliding object. If it is checked you can use methods like OnTriggerEnter2D or OnTriggerEnter.

Apart from these, there are pre-requisites to detect Collisions.

  1. A Collider component should be added.
  2. A Rigidbody component should be added.
  3. The Collision event handling method like OnCollisionEnter, OnCollisionStay, OnTriggerEnter, OnTriggerStay, OnCollisionEnter2D, OnCollisionStay2D, OnTriggerEnter2D or OnTriggerStay2D should be used.