Can you guys help me figure out what’s up with this code? It’s a scene selection menu. I have an array of buttons. If you click a button, it uses the GetLevelNumber() to figure out which level number it is, and then uses ClickLevelButton() to load that level. I open to better ideas on how to do this, but right now in the editor, it works perfectly with no warnings or errors, no null exceptions. But, when I build to the device, it hangs up when I press a button, and Xcode gives a Bad_Access Error on the object that has this script assigned to it. Can any of you see what I’m missing?
Thanks in advance!
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
public class UI_Manager : MonoBehaviour
{
public DataControl dataScript;
public GameObject[] levelButtons;
public Text levelTextObject;
public string levelString;
static public int levelNumber;
public Text loadLevelIndicator;
public Text arrayNumberIndicator;
void Start()
{
dataScript = GameObject.FindGameObjectWithTag("DataControl").GetComponent<DataControl>();
Debug.Log ("Current Level Number is: " + levelNumber);
dataScript.Load();
}
public void ClickLevelButton(GameObject button)
{
GetLevelNumber(button);
Application.LoadLevel("Level" + levelString);
}
public void GetLevelNumber(GameObject button)
{
levelTextObject = button.GetComponent<Text>();
levelString = levelTextObject.text;
bool isSuccess = int.TryParse(levelString, out levelNumber);
if(isSuccess)
{
loadLevelIndicator.text = "Load Level: " + levelNumber;
arrayNumberIndicator.text = "level Buttons[" + (levelNumber - 1) + "]";
}
else
{
loadLevelIndicator.text = "Can't Get Number!";
}
}
public void LoadMenu()
{
if(dataScript.firstPlay)
{
//play movie
//dataScript.firstPlay = false;
//dataScript.Save();
Handheld.PlayFullScreenMovie("Intro.mp4", Color.white, FullScreenMovieControlMode.Hidden, FullScreenMovieScalingMode.AspectFit);
Application.LoadLevel("LevelSelect01");
}
else
{
Debug.Log ("NOT FIRST PLAY: Loading Level Selection Screen...");
Application.LoadLevel("LevelSelect01");
}
}
}