Unity3d无法正确加载场景

时间:2015-07-22 07:39:47

标签: c# android unity3d

我正在用一个按钮加载一个场景并将一个参数传递给一个单例(从主菜单场景到游戏场景)。代码如下所示:

public void OnPointerClick(PointerEventData data)
    {
        if (data.selectedObject != null)
        {
            string name = Tools.GetLast(data.selectedObject.name, 2);
            selectedChapter = int.Parse(name);
            DataHolder.holder.selectedChapter = selectedChapter;
            Application.LoadLevel("Book_Scene");
        }
    }

我有不同的按钮,可以在书籍场景中加载不同的章节。第0章一切正常。其他任何东西和应用冻结了。奇怪的是,书籍场景中的代码似乎在运行,因为特定章节的叙述开始了,但这是唯一可行的。真正令我困扰的是,当我在视觉工作室中调试它并逐行扫描断点时,所有工作都很精细,场景加载到正确的章节等等。此行为未连接到visual studio或统一编辑器,因为错误持续存在于我所做的android构建中。我也没有在控制台中出错。 Unity刚刚停止响应。

这是播放声音等的开始方法:

 void Start () {

        currentPageIndex = DataHolder.holder.selectedChapter;
        flag = true;
        if (currentPageIndex == 0)
        {
            for (int i = 0; i < pages.Length; i++)
            {
                CanvasGroup canGroup = pages[i].GetComponent<CanvasGroup>();
                canGroup.alpha = 0.0f;
            }
        }
        else
        {
            if (Language.CurrentLanguage() == LanguageCode.EN)
            {
                //This line gets called since the sound starts playing even during the Editor freeze
                AudioHelper.CreatePlayStackingSound(AudioManager.holder.voiceOversEnglish[currentPageIndex], 1f, "voiceOver");
                // This does not get output to the console.
                Debug.Log("Scene " + Application.loadedLevelName + "is loaded after sound");
            }
            if (Language.CurrentLanguage() == LanguageCode.AR)
            {
                AudioHelper.CreatePlayStackingSound(AudioManager.holder.voiceOversArabic[currentPageIndex], 1f, "voiceOver");
            }
            Transform currPagetext = pages[currentPageIndex].transform.Search("TextPage" + currentPageIndex.ToString());
            currPagetext.gameObject.AddComponent<TextTyper>();
            initPage(currentPageIndex);
        }
        entrance = false;
        done = true;
        direction = true;
        Debug.Log("Scene " + Application.loadedLevelName + "is loaded ");
    }

1 个答案:

答案 0 :(得分:0)

问题解决了。由于某些浮点不精确,有一个do {} while()循环卡住了。我仍然不知道为什么在OnPointerClick()中添加断点不会导致循环卡住。