- Home /
Level Not Loading when enemy dies
In my game when the enemy dies it doesnt load the next level and also here is the code I used` using UnityEngine; using UnityEngine.SceneManagement;
public class Target: MonoBehaviour { public float health = 50f;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
}
void Die()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
} `
Answer by Beylan0 · Jul 04, 2020 at 11:36 AM
Have you added your scenes properly in your build settings? .buildIndex depends on the index value of the scenes in build settings. @flynnonthemoon
Answer by ray2yar · Jul 04, 2020 at 11:20 PM
Is it possible that damage is repeatedly being applied so that you are repeatedly loading the next scene? Put simply - can it be that the enemy dies, level starts loading, enemy dies AGAIN before the next scene loads so another load starts.... and so on?
Your answer
Follow this Question
Related Questions
Loading level after sound plays 1 Answer
Scene not loading properly everytime 3 Answers
Multithreaded chunk loading 1 Answer
timed out load level 2 Answers
Wait n-seconds before loading level 1 Answer