- Home /
How to load a GameOver scene after my charactor's health reaches 0,How do I load a GameOver scene after my health reaches 0?
Here's my health script
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class HealthBarController : MonoBehaviour { public Image healthBar; public float health; public float startHealth;
public void onTakeDamage(int damage)
{
health = health - damage;
healthBar.fillAmount = health / startHealth;
if (health <= 0)
{
Destroy(gameObject);
}
}
}
Comment
Answer by omelettewiz · Jan 20, 2021 at 11:13 PM
Use SceneManager.LoadScene
.
if (health <= 0)
{
Destroy(gameObject);
SceneManager.LoadScene("YourScene", LoadSceneMode.Single);
}
It keeps saying "Scene 'Game Over' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded. To add a scene to the build settings use the menu File->Build Settings..."
Your answer
![](https://koobas.hobune.stream/wayback/20220613023701im_/https://answers.unity.com/themes/thub/images/avi.jpg)