Raycasting Through Terrain

I need to check to see if an object is about to walk into water. What I need the object to do is turn around so it doesn’t walk into it. I’ve set up a water collider just below the water itself, and I have it so the object is raycasting to the ground slightly in front of him. Unfortunately, since the water collider runs under the terrain, even if the object is on the terrain and the raycast doesn’t hit any visible water, it raycasts through the terrain to the water below, and the AI keeps reacting like its about to run into the water. Why is that, and how should I fix it?

Raycasting every frame is not efficient. Simply make the water collider a trigger and use something like the following code to check the collision:

function OnTriggerEnter(object : Collider) {
    if(object.tag == "Water") {
        //turning code
    }
}

Just set up your water collider to have the tag ‘Water’. this is the technique used by ‘Burg Zerg Arcade’ in his video tutorial : Video Tutorial