Unity3d没有正确加载场景
本文关键字:加载 Unity3d | 更新日期: 2023-09-27 18:04:10
我正在加载一个带有按钮的场景,并将参数传递给singleton(从主菜单场景到游戏场景)。代码看起来像这样:
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中调试它并逐行使用断点时,一切都很好,场景加载到适当的章节等等。这种行为与visual studio或unity编辑器无关,因为我所做的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 ");
}
问题解决。有一个do{}while()循环卡住了,由于一些浮点不精确。我仍然不知道为什么在OnPointerClick()中添加断点不会导致循环卡住。