AI Character goes through walls when using Transform

I made AI enemy that follows the player when the needed distance is met. I used Transform. But the enemy goes through walls. How can I fix the problem without changing the whole code? Thank you for your answer in advance! Here is my code:

using UnityEngine;
using System.Collections;

public class EnemySkeleton : MonoBehaviour {
public Transform player;
static Animator anim;

// Use this for initialization
void Start () {
    anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update () {
    
    if (Vector3.Distance(player.position, this.transform.position) < 10)
    {
        Vector3 direction = player.position - this.transform.position;
        direction.y = 0;
        this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
            Quaternion.LookRotation(direction), 0.1f);
        anim.SetBool("IsIdle", false);
        if (direction.magnitude > 2)
        {
            this.transform.Translate(0, 0, 0.08f);
            anim.SetBool("IsWalking", true);
            anim.SetBool("IsAttacking", false);
        }
        else
        {
            anim.SetBool("IsWalking", false);
            anim.SetBool("IsAttacking", true);
        }
    }
    else
    {
        anim.SetBool("IsWalking", false);
        anim.SetBool("IsAttacking", false);
        anim.SetBool("IsIdle", true); 
    }
}

}

You can’t. Transform are used to move objects but no check is done with walls because wall penetration check is done by the physic engine. You have to move your NPC with physic request using a collider.

Moreover, you may want that the NPC follows a path to the player and not a straight line to him. Because if your player is turning right (or left) and there is a wall between the two of them, your NPC will just slide on it (best case scenario) if the collision is active.

So you need both modules to have a proper AI.

When moving characters and we want collision, best to use Character Controller or RigidBody’s AddForce implementation as they handle a lot of stuff Transform doesn’t.