Access variable from script on other gameobject.

I’m trying to access a variable from another gameobject to reference it but i’m not having any luck since i only know how to do it if the components are all on the same object.

Here’s a simplified version of the 2 scripts without the extra functions.

Enemy_Attacked.js on Enemy

var MeleeInstance;
 
 
function Start () {
Meleeinstance = GetComponent(Melee);   
}
 
function Update () {
}
 
    function OnTriggerEnter (col : Collider)
    {
       
        if(MeleeInstance == true)  
        if(col.tag == "Weapon")
        {
        MeleeInstance.swordReady = false;     
        }
    }

Melee.js On player
Code:

    public var Enemy_Attacked_Instance;
     var swordReady : boolean = false;
   
    function Start () {
     Enemy_Attacked_Instance = Enemy_Attacked;
 
    }
     
    function Update ()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            swordReady = true;
            StartCoroutine("DisableSwordReady");
        }
    }
   
    function DisableSwordReady()
    {       
        yield WaitForSeconds(1);
        swordReady = false;
}

Try

MeleeInstance = GameObject.FindObjectWithTag("Player").GetComponent.<Melee>();

or whatever the JS equiv is

This site has great tuts on getting components from script a / script b