Kill the Player?

I made this script, but I cant seem to figure out how to make him die. I would like the scene to reset when his health hits 0. Here is the script:

using UnityEngine;
using System.Collections;

public class EnemyAttack : MonoBehaviour {
	public GameObject target;
	public float attackTimer;
	public float coolDown;
	

	// Use this for initialization
	void Start () {
		attackTimer = 0;
		coolDown = 2.0f;
	
	}
	
	// Update is called once per frame
	void Update () {
		if(attackTimer > 0)
			attackTimer -= Time.deltaTime;
			
		if(attackTimer < 0)
			attackTimer = 0;
		
		if(attackTimer == 0){
			Attack();
			attackTimer = coolDown;
	
	}
}

	private void Attack(){
		float distance = Vector3.Distance(target.transform.position, transform.position);
		
		Vector3 dir = (target.transform.position - transform.position).normalized;
		
		float direction = Vector3.Dot(dir, transform.forward);
		
		if(distance < 2.5f) {
			if(direction > 0) {
				PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
				eh.AddjustCurrentHealth(-10);
			}
		}
	}
}

At the very end of your Attack function you should check if the players current health -10 <= 0 , if so run whatever method you have for that. It most likely is also on the players script, so just call the function if that conditional is met.

if(direction > 0) {
    PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");

    if(eh.health-10 <= 0) //eh.Killed();
    else eh.AddjustCurrentHealth(-10);
}

Depending on if you display the health after you die, you may want to either subtract the health first and then run the conditional check or just subtract the 10 from the Killed() function itself. Either or, but not both :wink: