Get an array from a different script.

I have been looking around for the answer for a few days now, my question is how do I get an array from a diffrent script?

Here is what I have done so far (JS)

script_1(On an object with tag Leader_1):

34272-script_error_2.png

script_2(On a sepertate object):

But I am getting an error which says:

BCE0019: ‘List_Of_Leaders’ is not a member of ‘UnityEngine.Component’.

Any help is welcome.

When you mark something as static, in particular a variable(property/field), every thing that uses that class shares it and it transcends instances(they all share the pointer to that value). This is a static class member rather than a instance member. YouTube video explaining it.

Point is, to gain access to it all you need to do is:

List_Of_Enemy = ClassName.List_Of_Leader; // Not an instance, but the class, in Java/UnityScript this is the name of the file(typically unless you specify the class explicitly).

In C# it’s literally the name of the class that contains the declaration.

What if you did something along these lines:

Script 1

function ReturnLeader() : ArrayList {
    //you could also make it an array and do "return List_Of_Leader.ToArray();"
    return List_Of_Leader;
} //you might have to make the function public or whatever, my UnityScript is rusty since I'm recently a C# guy

Script 2

List_Of_Enemy = GameObject.FindGameObjectWithTag("Leader_1").GetComponent("Script_1").ReturnLeader();
//Is it FindGameObjectWithTag or just FindWithTag? That could have been your problem, as well.

I fixed it I used this(JS):

List_Of_Enemys = GameObject.FindWithTag(“Leader_1”).GetComponent(Script_1).List_Of_Leaders;

As you see the GetComponent doesn’t have quotation marks, and now it works.