- Home /
Question by
public void username · Jan 31, 2016 at 09:38 AM ·
androidcrashcrashingcollectiblecollect
Android Game crashing when collecting collectibles
I'm currently making an Android game (it's my first one) in which you can collect rotating coins (in fact they are just white cubes.) The code for collecting them looks like this:
public class Collect : MonoBehaviour
{
[HideInInspector]
public Text collectiblesText;
private GameObject collManager;
void Start()
{
collManager = GameObject.Find("CollectibleCounter");
collectiblesText = GameObject.Find("CollectiblesText").GetComponent<Text>();
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
{
collManager.GetComponent<CollectibleManager>().collectibleCount++;
collectiblesText.GetComponent<Text>().text = collManager.GetComponent<CollectibleManager>().collectibleCount.ToString();
PlayerPrefs.SetInt("Coins", collManager.GetComponent<CollectibleManager>().collectibleCount);
gameObject.SetActive(false);
}
}
}
In the Unity Editor everything works fine, but the actual Android game crashes and closes sometimes when collecting one of these coins. This crash happens only sometimes, nearly every fifth coin. Please tell me if you see the problem or just know some good Android debugging tools. If you miss some important information, write a comment and I'll add it.
Thanks for your help, Luke
Screenshots:
Overall view with coin selected
Overall profiler at frame of collecting
Comment