need some tips making my AI avoing a hole

need some tips making my AI “avoiding” a hole
sorry keyboard mistake

this is my current script

var attackDamage:int;
var attackSpeed:float;
var attackDistance:float;
var viewDistance:float;
var movingSpeed:float;

private var target:GameObject;
private var eachAttackTime:float;


function Start()
{
	eachAttackTime = 0;
}
function Update () 
{
	var target = GameObject.Find("mainCharacter");
	var hit:RaycastHit;
	eachAttackTime += Time.deltaTime;
	if(Vector3.Distance(gameObject.transform.position,target.transform.
	position) <= viewDistance)
	{
		gameObject.transform.LookAt(target.transform);
		gameObject.transform.position = Vector3.MoveTowards(gameObject.
		transform.position,target.transform.position,movingSpeed/100);
		
		var ray:RaycastHit;
		if(Physics.Raycast(gameObject.transform.position,target.transform.
		position,hit,attackDistance) )
		{
			if(hit.collider.gameObject == target   eachAttackTime >= attackSpeed)
			{
				eachAttackTime = 0;
				Attack();
			}
		}
		
	}

function Attack()
{
	Debug.Log("Attack!!");
}

this enemy is supposed to chase the player also i want to make my enemy detects if there is no ground ahead and find another route

i have Succeeded making it chasing my character but i have no idea how to make it smarter so its not so easy to
fall down.

i dont want to make an invicible wall around my level because i want my enemy to be able to fall (but not so easy)

pls help me im noob at unity and noob at programming as well :frowning:

thx

Do a raycast from say 1 unit in front of the character directly down and see if you hit anything. If not, stop or turn or something. Or use a pathfinding library.