Visibility Testing

I've seen a few posts here regarding how to test if an enemy is visible. The one I linked suggested using a mesh collider and if that hit the NPC that I could raycast. What I'm wondering is if there is a more refined method. It seems to me in this case if I don't pick the correct ray that the NPC would still remain hidden.

For example: An NPC is behind a hill and all that is visible, to my player, is his hat. The collider would say the NPC is in range but if I cast a ray from the center of my player's eye out chances are it's going to hit the hill.

The only way I can see to check real visibility is to cast a ray from the player's eye to ever vertex on the other mesh and break if I find any that aren't blocked but this would be very expensive.

Use several raycasts instead of just one. You don't need to check every possible point, just a few on the extremities.

You can try renderer.isVisible

http://unity3d.com/support/documentation/ScriptReference/Renderer-isVisible.html

Though this will return true if the renderer is visible in any camera including the editor view camera.

Really you don't need that level of accuracy in a game