Finding inactive objects


I’ve been trying to make my AI a little better, by checking if a light (that the player can turn on or off) is turned on or off, of course only when within range. Sometimes it finds the necessary object, sometimes it doesn’t. Here is a piece of code I wrote in C#:

public bool chasing;
public GameObject player;
public GameObject playerLight;

    void Start () {
    player = GameObject.FindGameObjectWithTag("Player");
    playerLight = GameObject.FindGameObjectWithTag("PlayerLight");
    //in the update function...
    void Update () {
    float dist = Vector3.Distance(transform.position, player.transform.position);
    if(... || && dist < playerLight.light.range){
    chasing = true
    if(... && !{
    chasing = false;

It seems really strange, how it sometimes happens to work, and other times it doesn’t…

OK, I fixed it by changing the intensity of the light and checking it in this script, so the object is never inactive. Works fine like that!