So I thought I had figured out static variables until I ran into this problem:
Works:
//ScriptOne
static var lot = new int[4];
static function output () {
var ret = lot[0];
return ret;
}
Doesn’t work:
//ScriptOne
class pig{
var weight:int=6;
}
static var lot = new pig[4];
static function output () {
var ret = lot[0].weight;
return ret;
}
//ScriptTwo
function Update () {
Debug.Log(ScriptOne.output());
}
NullReferenceEception on play
It appears that an array whose type is a custom class cannot be made static. Is there a workaround or a better way to do this that works? I am writing a script that I want to be treated as a library of functions and in this case there should only be one instance of the array at a time so it made sense to make it static. Am I missing something?