Boolean not toggling

I’m having a problem. Im trying to make that when i look at enemy isView goes to true. When i look away it’ll go false. Right now its not toggling at all. Whats the problem?

using UnityEngine;
using System.Collections;

public class enemyAI : MonoBehaviour {
	
public Transform player;

public bool isView = false;
 
void Update()
{
 isView = false;
		
			
	var Distance = Vector3.Distance(player.position, transform.position);
		
		
	 if(Distance > 30 && isView == false){
               Vector3 position = player.position;
               float distance = Random.Range(10.0f,20.0f);
               Vector3 objPosition = position - player.forward* distance;
               Vector3 startHit = objPosition;
               transform.position = objPosition;
}
	}
void OnWillRenderObject() {
	
		RaycastHit hit;

        if (Physics.Raycast(player.position, (transform.position - player.position).normalized, out hit)) {

            if (hit.collider.gameObject == gameObject)
		    {
				isView = true;
				
		    }

        }

    }

		
 }

You’re setting it to false at the start of your Update() function, and it remains false for every iteration of your main game loop.

The only time it can possibly be set to true is in OnWillRenderObject, which occurs just before rendering and too late for any useful game logic to be applied.

I got it working now. I had a gameobject called slender and a mesh parented to it. I put the code into the mesh and it now toggles.