Riddle me this, my friends…
When running this script:
var materialArray : Material[];
var thisObject : GameObject;
private var index : int = 0;
function Awake () {
thisObject.renderer.material = materialArray[index];
}
function Update () {
if (Input.GetKeyUp("1")) {
index--;
if (index < 0) {
index = materialArray.Length - 1;
}
thisObject.renderer.material = materialArray[index];
}
if (Input.GetKeyUp("2")) {
index++;
if (index > materialArray.Length - 1) {
index = 0;
}
thisObject.renderer.material = materialArray[index];
}
}
function OnMouseOver () {
GlobalVariables.DebugMessage = "Looking at me!";
Debug.Log ("OnMouseOver");
}
function OnMouseExit () {
GlobalVariables.DebugMessage = " Not looking at me!";
Debug.Log ("OnMouseExit");
}
I get the following error:
UnassignedReferenceException: The variable thisObject of 'CheckIfFocus' has not been assigned.
You probably need to assign the thisObject variable of the CheckIfFocus script in the inspector.
CheckIfFocus.Awake () (at Assets/Scripts/CheckIfFocus.js:7)
Now here’s the funny part: that GameObject has in fact been assigned (it’s the object the script is on), and what’s more…the script works! It does everything it is supposed to do (apart from the MouseOver/Exit), but still I get the error saying it doesn’t work. Is this a bug or am I completely overlooking something?

I’ve tried renaming the variable, making a new one, I’ve even tried exporting to a Unity package and importing in a new Project, as someone suggested. Nothing works.
Can anyone help me out with this mystery?
A post in the forums reports that this occurs when the same script is assigned to two different objects. See the thread I linked to. This is just a guess, but do you perhaps have the same problem?