I want a script where when my players health reaches 0 it sends them to a game over screen.
(This is in the same script as the healthbar)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Health : MonoBehaviour {
//health reference
private const float MAX_HEALTH = 100f;
public float health = MAX_HEALTH;
//health bar
private Image healthBar;
// Start is called before the first frame update
void Start()
{
healthBar = GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
healthBar.fillAmount = health / MAX_HEALTH;
}
// de a t h
public void DealDamage(float damage)
{
if ((health -= damage) < 0f)
{
Die();
}
}
private void Die()
{
SceneManager.LoadScene("GameOver");
}
}