import variable help!

Hi, i want to import a variable from a script to another script. Can you help me ? Cheers!

I am assuming you want to read the variable of another script.

Scripts are classes inside Unity3D (assuming the MonoBehaviour types, which is the default for JavaScripts). The name of the class is the file-name of the script.

You can use GetComponent(name of class) to retrieve instance of the class/behaviour in the same game object:

// Foo.js
public var my_foo:int;

function Awake() 
{
      my_foo = 1;
}

// FooBar.js

function Start()
{

    var foo:Foo = GetComponent(Foo);
    Debug.Log(foo.my_foo);
}

Both Foo and FooBar must be attached to the same game object. For passing of variables between different game objects, you have to do this

var target:GameObject = GameObject.Find("Target");
var foo:Foo = target.GetComponent(Foo);

Or you can use static variables

// FooStatic.js
public static var my_foo:int;

And in some other scripts...

Debug.Log(FooStatic::my_foo);

Do note that static variables do have some quirks and you should research it before using it in your design.