create GUI.Label and then access to it..

Hi!
So need to create GUI.Label and then access to it…

first script :

test.js

Code:

var style : GUIStyle;


public var SCORE = "0";



function OnGUI () 


{


    style.fontSize=18;


    style.normal.textColor=Color.red;   


    GUI.Label (Rect (Screen.width*0.2, Screen.height*0.15, 100, 20), SCORE,style);


}

test_access.js

Code:

function Start()


{


    var LOAD : test;


    LOAD = GetComponent(test);


    LOAD.SCORE="1";


}

test and test_access - both different object…
error NullReferenceException: Object reference not set to an instance of an object

If you have the scripts on a different object you have to tell it which object to look for.

var myObject = GameObject.Find("ObjectsNameHere");

LOAD = myObject.GetComponent(test);

You need something in test_access.js that refers to the component with test.js on it - then call GetComponent on that - or just assign it in the inspector:

#test_access.js#

  var theOtherObject : test;
function Start() {

     theOtherObject.SCORE = "1";

}

Or:

var otherObject : GameObject;

function Start() {

    otherObject.GetComponent(test).SCORE = "1";

}

Please remember naming conventions really help - your scripts (and their inherent classes should start with a capital). Variables should start with a lower case letter and then be Camel case. All upper case implies a constant or preprocessor defined value.