I hope this is a simple problem to solve, but it seems to be the only scripting error I have at the moment and I’m not sure how to solve it.
It’s for a GUI script to show the amount of orbs the character has created but I get the error;
UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don't use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
livesGui..ctor () (at Assets\Scripts\GUI\livesGui.js:4)
And this is the code;
var guiSkin: GUISkin;
var textFieldString = "text field";
var livesString = "Orbs:";
var scorecontrol : ThirdPersonStatus = GetComponent(ThirdPersonStatus);
function OnGUI () {
livesString = "" + scorecontrol.lives;
textFieldString = GUI.TextField (Rect (145, 125, 100, 30), livesString);
}
I have tried to do what the error log told me to, but it hasn’t worked. Any help will be greatly appreciated.