Cannot get enemy script to recognize light component on player

Hey, I’m really new at using Unity and coding in general, so I am probably doing something really stupid here, but I cannot for the life of me figure this out.

I want to have an enemy begin to follow a player if they come within the range of the light component on the player. I am getting an error

" The name `player’ does not exist in the current context "

Here is the code I am working with.

using UnityEngine;
using System.Collections;

public class EnemyController : MonoBehaviour 
{
	public float attackRange;

	void Start ()
	{
		GameObject player = GameObject.FindWithTag("Player");
		player.GetComponent<Light>();
		attackRange = Vector3.Distance (player.transform.position, gameObject.transform.position);
	}
	
	void Update () 
	{
		
		if(attackRange = player.Light.range)
		{
			transform.localPosition = new Vector3(0, 0, 0);
		}
		
	
	}
}

If the transform looks odd, it’s because I am short on time and made the Enemy a child of the player so the local position for the player is 0,0,0 .

The specific error you are getting is because you declare ‘player’ inside Start(). ‘player’ is a local variable to Start() and will not exist outside the scope. You need to delcare player at the top of the file and initialize it inside start. Also Line 11 doesn’t do anything. As for line 18, ‘Light’ with an upper case ‘L’ does not exist as a property of a game object. Assuming that game object has a light component, it would be ‘light.’ And on line 18, double equal (‘==’) is the comparison operator, but you don’t want to be directly comparing two floats. You want to use ‘<=’.

So the code that compiles is:

using UnityEngine;
using System.Collections;
 
public class EnemyController : MonoBehaviour 
{
    public float attackRange;
	private GameObject player;
 
    void Start ()
    {
       player = GameObject.FindWithTag("Player");
       attackRange = Vector3.Distance (player.transform.position, transform.position);
    }
 
    void Update () 
    {
       if(attackRange <= player.light.range)
       {
         transform.localPosition = new Vector3(0, 0, 0);
       }
 
    }
}