小编Ary*_*Dev的帖子

Unity 脚本在编辑器中工作正常,但在构建中却不行

我是 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)

c# build unity-game-engine

1
推荐指数
1
解决办法
3567
查看次数

标签 统计

build ×1

c# ×1

unity-game-engine ×1