If I create a class in one script is the class recognized by all scripts? If not how do I make it so.
If I make a variable in one script. How do I make it visible to all scripts.
Is there some doc about variable scope and public and private and whether it’s inside or outside a function and all that??
thanks,
Dan
Yep.
You can use a static variable:
Script1.js:
static var something = 2;
Script2.js:
Script1.something = 4;
As long as it’s a public variable, though, you can still access it from other scripts using GetComponent. Static variables are a little more convenient, but sometimes that’s not what you want.
Not sure about docs, but in Unity Javascript:
var something = 2; // public, global scope
private var somethingElse = 3; // private, global scope
function Start () {
var foo = 1; // local scope
for (var i : int = 0; i < 10; i++) {} // local scope for function but not this loop
for (var i : float = 0.0; i < 10.0; i++) {} // error, i is already defined in this scope
}
–Eric