So I have read some of the same question, and it’s said that it’s caused by #pragma strict where I should init var in Awake or Start. But my problem is, so…
This is my code before and it’s working fine
#pragma strict
var aa : SomeType;
var bb : OtherType;
var dd = "start";
var ee = "pause";
Then I add
#pragma strict
var aa : SomeType;
var bb : OtherType;
var xx = transform.position;
var yy = transform.rotation;
var dd = "start";
var ee = "pause";
That error happened, so after searching here and there, I changed it to:
#pragma strict
var aa : SomeType;
var bb : OtherType;
var xx : Vector3;
var yy : Quaternion;
var dd = "start";
var ee = "pause";
function Start() {
xx = transform.position;
yy = transform.rotation;
}
Error sticked.
Then I removed the xx and yy from all places and it went back to the first code, error still sticked, eventho before it’s running. So I restarted Unity and MonoDevelop, error’s gone and code running smoothly even after being added with var xx and yy like in the third code. Why did that happen?
Sometimes if you rapidly switch between Unity and MonoDevelop, Unity doesn’t recognise that the file’s timestamp has changed and thus not recompiling your script so the changes made don’t take effect.
If something happens again, just switch back to MonoDevelop, change a bit (like adding an empty line somewhere) and save the file again. When ou switch back to Unity you should see a small busy circle at the bottom right when Unity recompiles your script. If not, try selecting your script, press the right mouse button and select “reimport”, that usually fix it. Of course if your script still contains errors they won’t go away ^^