Chasing Enemy travels through walls

This has appeared several times on unity but I have not been able to find a fixed piece of code. Could someone please provide an altered piece of code to prevent the chasing enemy from traveling through walls. This is the code I got from another question on UA:

#pragma strict

var target : Transform;
var moveSpeed = 240;
var rotationSpeed = 180;
var myTransform : Transform;
 
function Awake()
{
    myTransform = transform;
}
 
function Start()
{
     target = GameObject.FindWithTag("Player").transform;

}
 
function Update () {

    myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
    Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
 
    myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime; 
 
}

It was acquired from How to create a basic follow AI - Unity Answers
One comment mentioned about applying rigidbody forces but didn’t show how to place it into the script. Thanks for the help!

You have to add a “Character Controller” and for moving use this:
var control : CharacterController;

//move the enemy
control.Move(Vector3(0,0,1));