- Home /
Destroy(gameObject); working in editor but not on android..
I'm trying to remove my main player object and replace it with a prefab when the player dies. I'm calling the following method when the player loses all of its health:
void playerDead()
{
Instantiate(playerHurt, transform.position, Quaternion.identity);
gc.updateHighScore(gold);
Destroy(gameObject);
}
It works absolutely fine in the editor, but when I run it on android its behaving oddly. It instantiates the playerHurt Object but doesn't destroy itself afterwards. Does anyone have any ideas as to why this could be happening?
make your build a development build with script debugging enabled. run the game and attach mono as the debugger. Set a break point to each line of the code and see if they all execute. See this doc for more information on the topic:
http://docs.unity3d.com/$$anonymous$$anual/Attaching$$anonymous$$onoDevelopDebuggerToAnAndroidDevice.html
Have you checked the logs? One possibility that springs to $$anonymous$$d is that for some reason gc
(whatever that is) doesn't exist and so a NRE is being thrown and the Destroy line isn't reached.