Cube goes through colliders

The cube goes though colliders. I want to limit how far it can move (only right and left controls) i think it ignores colliders due to “transform.Translate(dir * speed);”
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{

public float speed = 15f;
public float mapWidth = 5f;

void Start()
{
  
}

void Update()
{
    Vector3 dir = Vector3.zero;
    dir.x = -Input.acceleration.y;
   
    if (dir.sqrMagnitude > 1)
        dir.Normalize();

    dir *= Time.deltaTime;
    transform.Translate(dir * speed);
}

void OnCollisionEnter3D()
{
    FindObjectOfType<GameManager>().EndGame();
}

}

I think it’s beacouse there is no builded in function like OnCollisionEnter3D(), you need to use OnCollisionEnter() instead.