How can you prevent players from walking through Box Collider 2D?

At the movement I have a player which can roam freely around a 2D, top-down environment. He can currently walk through what I want to be walls and obstacles but I’m trying to find a way to prevent that. At the moment I’m using Box Collider 2D on both sprites but when using the current code they can still walk through.

public class PlayerMovement : MonoBehaviour {
    //The speed of affected characters
    float speed = 1f;
    public BoxCollider2D frameWallHitboxes;
    public BoxCollider2D frameCharacter;
    public void Update()
    {
        if (Input.GetKey(KeyCode.A)) //This is what should happen if I walked left into a collusion box
        {
            if (frameCharacter.IsTouching(frameWallHitboxes)) 
            {
                //movement should be blocked if they're touching a wall
            }
            else
            {
                transform.position += Vector3.left * speed * Time.deltaTime; //moves as normal
            }
        }
}

I think something may be wrong with the 10th line, does anyone know a possible solution?

I’ve decided to completely replace my movement with physics allowing me to use the colliders properly

public class PlayerMovement : MonoBehaviour {
    //The speed of affected characters
    public float speed = 40f;
    public BoxCollider2D frameWallHitboxes;
    public BoxCollider2D frameCharacter;
    public Rigidbody2D bodyCharacter;
    public void Update()
    {
        if (Input.GetKey(KeyCode.A))
        {
            bodySkipLevey.AddForce(gameObject.transform.right * speed * (Time.deltaTime * 2000) * -1);
        }
    }
}

It’s much more effective now