c# how to change player location on 0 hp

i’m looking to change the player location from anywhere on 0 PlayerHealth

i have a specific location i want the player to end up when PlayerHealth is 0
and is it possible to add this to the player health script or should it be its own script accessing it

for if im to add to this under if(curHealth <= 0) the ??? is the answer i couldn’t find


/// PlayerHealth.cs
/// Display the players health in game
/// Attach this class to your player character
using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;

public float healthBarLength;

// Use this for initialization
void Start () {
	healthBarLength = Screen.width / 2;

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

void OnGUI() {
	GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);

public void AddjustCurrentHealth(int adj) {
	curHealth += adj;
	if(curHealth < 0)
		curHealth = 0;
	if(curHealth > maxHealth)
		curHealth = maxHealth;
	if(maxHealth < 1)
		maxHealth = 1;
	if(curHealth <= 0)




healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);



It’s better to keep your components separate, a health script manages your player’s health, a shooting script is for shooting, etc. (If you wanna go component-based design, and not OOP where everything related to your player, is in your player’s script/class)

That job (what you’re trying to do) sounds to me is suitable to fit inside a GameManager or GameController script, which should be responsible for what happens when your player dies, how do you earn score, deaths, kills, etc. (Much like the GameController in UDK) - I advice you to create that script and put such things in it.

That Manager/Controller could be a singleton. Then, you have multiple ways to inform the manager, about the death of your player (reaching 0 health)

1- Create a public void Notify_PlayerDead() method inside your controller, that you call when the player dies, do your stuff inside it.

2- A more professional way would be to use events, create an OnPlayerDeath event and have -whoever needs to be notified about this event- subscribe to it. See events and observer pattern. (Link1, Link2, Link3)