我是 Unity 的新手。我最近创建了一个脚本,该脚本可以禁用场景中的按钮,直到满足条件(对于关卡选择菜单,禁用所有关卡,直到玩家完成之前的关卡)。但问题是 - 当我在Editor
中运行游戏时,我的脚本工作正常,但是当我构建然后运行游戏时,脚本无法 *正确工作* 。
这是该脚本 -
// 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 …Run Code Online (Sandbox Code Playgroud)