Accessing a script from another script

The first set of code below works. The second set is able to access the game object Enemy but doesn’t access the EnemyScript.

How do I write that script so I don’t have to drag and drop into the inspector every time I build a scene. Meaning, I want Enemy and Enemy Script to not be public be reference in the start function, but i only get a Null Reference error for the EnemyScript.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class GameControllerTest : MonoBehaviour {
    public GameObject Enemy;
    public EnemyController EnemyScript;
    public bool PlayerInSightTEST;
    void Start()
    {
        Enemy = GameObject.FindGameObjectWithTag("Enemy");
        EnemyController EnemyScript = Enemy.GetComponent<EnemyController>();
    }
    void Update()
    {
        if (EnemyScript.playerInSight)
        {
            PlayerInSightTEST = true;
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class GameControllerTest : MonoBehaviour {
   
    GameObject Enemy;
    EnemyController EnemyScript;
    public bool PlayerInSightTEST;
    void Start()
    {
        Enemy = GameObject.FindGameObjectWithTag("Enemy");
        if (Enemy != null)
        {
            EnemyController EnemyScript = Enemy.GetComponent<EnemyController>();
            if (EnemyScript != null )
            {
                Debug.Log("EnemyScript found");
            }
            else
            {
                Debug.Log("EnemyScript NOT found");
            }
            Debug.Log("Enemy object found");
        }
        else
        {
            Debug.Log("Enemy object NOT found");
        }
    }
    void Update()
    {
        if (EnemyScript.playerInSight)
        {
            PlayerInSightTEST = true;
        }
    }
}

If the 2nd script is not getting the EnemyController script reference either there is no object active in the scene with the tag Enemy at the time Start runs, or the object tagged Enemy does not have an active EnemyController component.

Thanks for the response.

Have both an object in the scene with the tag “Enemy” and it has an active enemy controller component.

I added another object “Player1” and its component PlayerScript, this seems to work bu the EnemyScript get component doesn’t unless i make the EnemyController Public.

thanks again.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class GameControllerTest : MonoBehaviour {
  
    GameObject Enemy;
    EnemyController EnemyScript;
    GameObject Player;
    PlayerController PlayerScript;
    public bool PlayerInSightTEST = false;
    public bool PlayerDestroyed = false;
    void Start()
    {
        Enemy = GameObject.FindGameObjectWithTag("Enemy");
        EnemyScript = Enemy.GetComponent<EnemyController>();
        Player = GameObject.FindGameObjectWithTag("Player1");
        PlayerScript = Player.GetComponent<PlayerController>();
        
}
    void Update()
    {
      
      
        if (EnemyScript.playerInSight)
        {
            PlayerInSightTEST = false;
        }
      
        if (PlayerScript.PlayerDestroyed)
        {
            PlayerDestroyed = true;
        }
    }
}