Reputation: 2167
I'm loading a scene with a button and passing a argument to a singleton(From the main menu scene to the game scene). The code looks like this :
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");
}
}
I have different buttons that load different chapters in a book scene. Everything works ok with chapter 0. Anything else and the app freezes. The wierd thing is that code from the book scene seems to run, since the narration for the specific chapter starts, but that the only thing that seems to work. What is really bothering me is that when I'm debugging it in visual studio and going line by line with breakpoints EVERYTHING WORKS FINE, the scene loads on the proper chapter and so on. This behavior is not connected to visual studio or the unity editor since the error persisted in a android build that I did. Also I get no errors in the console. Unity just stops responding.
This is the start method that play the voice over and so on:
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 ");
}
Upvotes: 0
Views: 236
Reputation: 2167
Problem solved. There was a do{}while() loop getting stuck due to some floating point imprecision. I still dont know why adding a breakpoint in the OnPointerClick() doesnt cause the loop to get stuck.
Upvotes: 0