How to access variables between scripts in unity JavaScript?

I made a game have two objects in the hierarchy panel. One called GameScreen and another called Clock I set up. Each has its own script attached. GameScreen uses game.js and the other uses clock.js.

When I win the game a popup box appears and says, “You’ve won!” This is caused by the game.js script. However, the clock.js is still running, so my clock is still counting down. When the time is up the clock.js makes a popup box saying, “you lose!”

This causes for a “you win” screen to pop up when you win and then later a you lose screen to appear. As you can probably guess, this is super annoying. If there was a way I could change variables in one script from another, I could get the clock to stop when you won or I could get the game to stop when the time ran out.

Is there some way to do this??

For example here are two javascript files. I want the first one to change the variable changeMe in the second to two.


function start(){



var changeMe:int;

I would do something like this…


var changeMeScript : 2.js; //this also needs to be set in inspector
    function Start(){


var changeMe : int = 129731239786;  //change this to whatever you want...
    function changeVariable () {
    changeMe += 1273612873; //change this also to whatever...

Haven’t tested it officially though… So no promises.

hey, to access variable do this :

first scripts :

static var test : int;

Second Script :

function Start ()
   var lol = (The name of the script where there is the static variable).(the name of the variable);


I would do something like this:


var imported_second_script : second_script;
imported_second_script = GetComponent(second_script);

function Start () {
// sets changeMe in second_script to 20
imported_second_script.changeMe = 20;


var changeMe : int;

I haven’t tried this, though. And sorry for no syntax highlighting. It doesn’t seem to work for me.