Input Working in Editor but not in Build
I was creating a game where putting a specific code into the start screen would cause a cheat to activate. When I tested it in the editor, it worked perfectly. However once I built the game and began testing it there, it would not register the cheat at all, despite working perfectly in the editor. Here is the code I am using:
public static bool autoPlay = false;
private string[] cheatCode;
private int index;
// Use this for initialization
void Start()
{
cheatCode = new string[] { "up", "up", "down", "down", "left", "right", "left", "right", "b", "a" };
index = 0;
}
// Update is called once per frame
void Update()//Check for the cheat code
{
if (SceneManager.GetActiveScene().name == "Start")
{
if (Input.anyKeyDown)
{
if (Input.GetKeyDown(cheatCode[index]))
{
index++;
}
else
{
index = 0;
}
}
if (index >= cheatCode.Length)
{
autoPlay = !autoPlay;
Text changeAbleText = GameObject.FindGameObjectWithTag("ChangeableText").GetComponent<Text>();
changeAbleText.enabled = !changeAbleText.enabled;
index = 0;
}
}
print(index); //for testing sake
}
I tested it using an in-log editor, and apparently when the index is 10, it starts throwing NullReferenceException errors, and the occasional Array Index is out of range. Note that this does not happen in the editor.
Your answer
Follow this Question
Related Questions
NullReferenceException after build 1 Answer
Null Reference Exception in iOS build for some users. Not in Editor and cannot duplicate 0 Answers
NullReferenceError in Build but not the Editor,NullReferenceException in Build but not Editor. 0 Answers
What BuildTargetGroup option is the right for a linux build? 1 Answer
The variables modified in the inspector are not kept on build 0 Answers