script-references and public variables ...

i kind of fixed this already, but there’s one thing i’m still curious about. here’s my problem:

i have a variable that contains a reference to a script, it doesn’t always contain the same type of script, but all the scripts it can contain have a public variable with the same name. basically i’m just trying to access that public variable. it works if i do something like this:

private var scriptRef;
private var temp : int = 0;

function Start() {
  scriptRef = anotherObject.GetComponent("otherScriptName");
}

function Update() {
  temp = scriptRef.publicIntVariable;
}

but since i always try to assign a type to every variable i tried this:

private var scriptRef : UnityEngine.MonoBehaviour;

but this throws an error “‘publicIntVariable’ is not a member of ‘UnityEngine.MonoBehaviour’”

i can’t use

private var scriptRef : otherScriptName;

either, because, as i said before, the variable can contain different types of scripts.

is there any ‘better’ way of doing this, or should i just keep using my generic-type variables?

The reason this doesn’t work is that your script will be treated as an instance of the base MonoBehaviour class. This class doesn’t have any of the extra variables or functions you would add to any subclass you make for scripting. Using the typeless variable is probably the easiest way to handle this.