Hi, I’m currently doing a game in Unity and I have a question regarding the destruction of my player object.
Currently I’m destroying the player with
public void PlayerDeath() { isDead = true; GetComponent<ScoreController>().SetEndLevelScore(); GetComponent<ScoreController>().SetTotalScore(); //ParticleSystem intantiatedParticle = Instantiate(deathParticle, transform.position, transform.rotation) as ParticleSystem; Debug.Log("Removing camera parent"); Camera.main.transform.parent = null; sceneLoader.GetComponent<SceneLoad>().StartCoroutine("LoadScoreScreenAfterDelay"); Debug.Log("Destroying player object"); Destroy(gameObject); Debug.Log("Player object destroyed"); }
Now this works when I use it in the editor: the player is destroyed, the main camera shows the scene for a few seconds and then the scene changes to the score scene. As you can see:
However, this is not working as it should when I’m playing the game from the built version. In this case the player GameObject model is still there, and the scene is frozen (the projectiles won’t move anymore) as shown here:
This also happens if I use gameObject.SetActive(false);
instead.
Anybody can tell me why it’s not working on the built game but it is on the editor? Thanks!