Accessing array in another script - Error message

I've got one script which defines an array (GUI_Main.js):

var thumbnailTextures : Texture2D[];

And a script (attached to another game object) that tries to access the first element from the thumbnailTextures array (AnotherScript.js):

GameObject.Find("GUI_Main").thumbnailTextures[0] = obj.renderer.material.mainTexture;

And I am getting the error message: Assets/Take Script.js(49,53): BCE0019: 'thumbnailTextures' is not a member of 'UnityEngine.GameObject'.

I think, I didn't really understand the concept of accessing variables in other scripts. Can somebody help me? Thx.

You are returning a GameObject. You should use GameObject.Find("GUI_Main").GetComponent("ScriptName").thumbnailTextures[0]

Most people don't so don't worry , it's something you learn by programming a lot. And a case of aspirin in the start.

The quickest way is to make an object instance of that script

class Foo()
   public int x = 3;
   private int y = 4;

class Bla()
    //Calls default constructor just ignore the whole constructor thing for now
    Foo myFooObjectInstance = new Foo();

    int myBlaInt_X = myFooObjectInstance.x;

    //NOT ALLOWED! private is blocking acces
    int myBlaInt_Y = myFooObjectInstance.y;

An array can be accesed the same way but you should really just store the array in where you need it and acces it there or use a get{}set{} which helps with reading/writing and letting the other script know you are "potentially" messing it up (But if all that's to much information for now just forget it ok)


It was just brought to my attention you may not have any use for C# , I think it's a bit of a waste to just delete this answer but I would like to apoligize for the sloppyness of the answer. I'm afraid I can not do much in JS support but wish you good luck!