Destroy Player when Cur_Health <=0

I recently created a health bar and it “works” in one way at least, and it recognizes collisions and such and i want to destroy my Player when my current health(cur_health) is equal to zero. It seems simple but everything i try doesn’t work. Also once my character is deleted how do i change scenes in game to my ending credits/Game Over? Below is my script if anyone can help me out it’d be greatly appreciated

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HealthScrpit : MonoBehaviour {

public Image healthbar;
public float max_health = 100f;
public float cur_health = 0f;
public bool alive = true;

void Start ()
{
    alive = true;
    cur_health = max_health;
    SetHealthBar();

}



public void SetHealthBar()
{
    float my_health = cur_health / max_health;
    healthbar.transform.localScale = new Vector3(Mathf.Clamp(my_health, 0f, 1f), healthbar.transform.localScale.y, healthbar.transform.localScale.z);
}

public void TakeDamage(float amount)
{
    if (!alive)
    {
        return;
    }

    if(cur_health <= 0)
    {
        cur_health = 0;
        alive = false;
        //gameObject.SetActive(false);
    }

    cur_health -= amount;
    SetHealthBar();
}

// Update is called once per frame
void Update () {
	
}

public void TakeDamage(int damageAmount)
{
    cur_health -= damageAmount;
    if (cur_health <= 0)
        Die();
    Destroy(this.gameObject);

}

private void Die()
{
    gameObject.SetActive(false);


}

}

I can see your character is deleted every time you take damage. That’s because you dont have any curly brackets on your if statement here:

 cur_health -= damageAmount;
 if (cur_health <= 0)
     Die();
 Destroy(this.gameObject);

It should be

 cur_health -= damageAmount;
 if (cur_health <= 0){
     Die();
     Destroy(this.gameObject);
    }

Otherwise, only the line right after the if-statment is executed when the statement is true, the line after that is executed every time TakeDamage() is called.

Regarding changing you scene, you do that via the scenemanager, like this:

UnityEngine.SceneManagement.SceneManager.LoadScene("Scene name");

(Or simplify it by writing “using UnityEngine.SceneManagement;” at the top, and then just use “SceneManager.LoadScene(“Scene name”);”

And why do you have two different methods called TakeDamage(), one accepting a float, and one accepting an int? It is the one accepting an int that is causing your player to be destroyed.