- Home /
Unity syntax error (I think is bug)
Yesterday when I coding the script, the computer automatic shut down. Then when I opened the monodevelop after opened Unity, it ask me to reload the automatic save version, I clicked "Yes". After that the Unity report me the syntax error. Such as the { cannot be using at the class and struct, a local variable not exist at current context .I check my script lots of times, I believe there were no any errors there and the script can be compiled at the monodevelop and Visual Studio. Then I try using the comment to located the error caused the unity to report accurately. Finally by move a method to other location (between other two methods), and move the declaration statement for the local variable to other position, the error fixed, but if move to the old position, the error will appear again. (All the processes are saved). So why caused this problem and how to fix it instead my method.
For easy to understand my problem. I show some simple examples below
public void method_A()
{
float a;
callmethod_B();
a = xxxxxxxx;
}
The script show at top is no error in Unity, monodevelop and Visual Studio. But if I change some code, the unity will report an error.
public void method_A()
{
callmethod_B();
float a;
a = xxxxxxxx;
}
The unity will report the error at the "a = xxxxxxxx;". The error said the "a" is not exist at current context
Thanks.
The only differences between actual code and sample code is the name of variable.
The actual code is:
public Vector3 get$$anonymous$$oveVectorTo$$anonymous$$ainCharacter()
{
if(!this.isDirectionFutherTo$$anonymous$$ainCharacter (currentDirection) && !this.isFontViewHasDetection())
{
return currentDirection;
}
float [] directions_distances = new float[4];
..............
//use of directions_distances, error
float bestDistance = directions_distances [0] + 1;
...............
}
The script at top caused the error when using the "directions_distances", the error message is "The name 'directions_distances' does not exist in current context"
when I change the position like below, the error disappear
public Vector3 get$$anonymous$$oveVectorTo$$anonymous$$ainCharacter()
{
float [] directions_distances = new float[4];
if(!this.isDirectionFutherTo$$anonymous$$ainCharacter (currentDirection) && !this.isFontViewHasDetection())
{
return currentDirection;
}
..............
//use of directions_distances, error
float bestDistance = directions_distances [0] + 1;
...............
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Make sure levels assets are loaded before switching? 1 Answer
Unity5 build issue, not showing texture. 1 Answer
2D Platformer Bug 0 Answers