I’m sure I’m missing something really basic here but I’m getting the following error when I stop running the game.
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.
UnityEngine.GameObject.FindWithTag (System.String tag)
play_slot…ctor () (at Assets/Standard Assets/Scripts/play_slot.js:1)
The script in question is this:
var slot = gameObject.FindWithTag("slot");
function Update () {
if (Input.GetKeyUp ("space")) {
print ("space key was released");
slot.animation.Play("play");
}
}
It sounds like I’m being told to write it like this:
var slot : gameObject;
slot = gameObject.FindWithTag(“slot”);
But then the variable disappears from the inspector, the game won’t run at all, and more error messages ensue.
Any help would be appreciated.
/Mark