Hello Unity Community, i have an Error that messes my builded game up with a report message, so heres the error i’v got:
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.
Pause Controller…ctor () (at Assets/Scripts/Pause Controller.js:2)
and heres the script the error comes from:
var menuHeight:float=500;
var menuWidth:float=500;
var buttonSpacing:float=25;
var mainMenu: String = "MainMenu";
var titleTexture:Texture2D;
var customSkin:GUISkin;
var customStyle:GUIStyle;
var Player: MouseLook = GetComponent(MouseLook);
var MainCamera: MouseLook = GetComponent(MouseLook);
function OnGUI(){
GUI.skin = customSkin;
GUILayout.BeginArea(Rect(Screen.width/2-menuWidth/2,Screen.height/2-menuHeight/2,menuHeight,menuWidth),customStyle);
GUILayout.Space(50);
GUILayout.Label(titleTexture);
GUILayout.Space(buttonSpacing);
Time.timeScale=0;
Screen.showCursor = true;
Player.GetComponent(MouseLook).enabled = false;
MainCamera.GetComponent(MouseLook).enabled = false;
if(GUILayout.Button("Resume Game")){
gameObject.GetComponent(PauseMenu).enabled = false;
Time.timeScale=1;
Screen.showCursor = false;
Player.GetComponent(MouseLook).enabled = true;
MainCamera.GetComponent(MouseLook).enabled = true;
}
GUILayout.Space(buttonSpacing);
if(GUILayout.Button("Exit to Desktop")){
Application.Quit();
}
GUILayout.Space(buttonSpacing);
GUILayout.EndArea();
}
i really hope to get this thing solved. thanks in advance ^^