Unity Scripts Working Fine in Editor, But not in Build
I am a Newbie in Unity. I recently created a script that disables buttons in a scene until a condition is satisfied (For a Level Selection Menu, to disable all levels until the player completes previous levels).
But the problem is - My script works fine when I run the game in Editor, but when I Build and then Run the Game, Script fails to Work Correctly .
Here is that script -
// Import required Modules
public class ButtonGatherer : MonoBehaviour
{
public List<Button> buttons;
public static int OpenLevels;
void Start()
{ if (OpenLevels == 0){
OpenLevels = int.Parse(File.ReadAllText(Application.persistentDataPath + "Data.gokartgo"));} //Reads Data from a file
GameObject[] btn = GameObject.FindGameObjectsWithTag("button");
for (int i = 0; i < btn.Length; i++){
buttons.Add(btn[i].GetComponent<Button>());
}
Debug.Log("Variable OpenLevels : "+OpenLevels);
for(int i = OpenLevels; i < buttons.Count; i++) {
buttons[i].interactable = false;
Debug.Log("Var i : " + i +", So Locked Level : " + buttons[I]); //Used This To debug and get values for variable i
}
}
}
I Have Also attached of the Screenshot of Debug Message That I Get -
When Running in Editor -
When Running After Building (Development Build) -
Please Help ....
Your answer
Follow this Question
Related Questions
Score counting works in editor but not when I build it! 0 Answers
Strange Memory Leak in Unity Editor 0 Answers
How to solve unity editor freezing at Application.EnterPlayMode in play mode after building? 0 Answers
Getting errors from BuildPipeline.BuildAssetBundles but not when building game... 1 Answer
How to change the project's Splash Image in a build? 0 Answers