I have a cube in my scene, and I want to get the x-scale in the form of a global variable. I used this:
static var BrickScaleX = (transform.localScale.x);
However, it doesn’t work. This is the error message it gives me:
“Assets/GetScale.js(1,27): BCE0020: An instance of type ‘UnityEngine.Component’ is required to access non static member ‘transform’.”
I want to be able to perform math functions on the x-scale of the cube, but I can’t do it this way.
Only declare variables outside functions; all actual code should be inside functions. Static doesn’t mean global; only add static if you actually want only one instance of it per class. If it’s public (which it is by default in JS), then it’s global. Also, it makes things easier to follow if you follow the convention of using lowercase for variable names, and uppercase for function and class names.
var brickScaleX : float;
function Start () {
brickScaleX = transform.localScale.x;
}