Check if Player can see Enemy.

I’m creating a Slender Script and i want slender to halt movement if the player can see him. How might i go about doing this?

function Update () {
var hit : RaycastHit;
if (Physics.Raycast (transform.position, -Vector3.up, hit)) {
if ( hit.collider.tag != “player” ){
…cannot see
…has vision of enemy

Use a Dot Product and a Raycast.

Check my answer here : How do you pick up pages like in "Slender"? - Questions & Answers - Unity Discussions