Health, Death and respawn help

Hi i am currently leaning unity and i have a little problem with my script and may be someone be able to help. My Player has a health bar that when goes down to 0 it will it show a message saying Dead in the corner because its a open world i would like to spawn the player when he dies to a Location on the map so the game can continue.

I have the PlayerHealth.cs but now there’s more to be added i have looked for hours on youtube to see if there’s a video but there’s nothing that’s fits what i would like to do. Also when the player gets hit by a near explosion like i tryed my own Rocket Launcher but my health stays full where it would be cool if it went down.

My player health script is this may help someone:

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
	public int maxHealth = 100;
	public int curHealth = 100;
	public bool dead = false;
	
	public float healthBarLength;
	
	// Use this for initialization
	void Start () {
	healthBarLength = Screen.width/2;
	}
	
	// Update is called once per frame
	void Update () {
	AdjustCurrentHealth(0);
	
	}
	
	void OnGUI () {
		GUI.Box (new Rect(0, 0, healthBarLength, 20), "");
		if (dead == true)
			Dead();
	}
	
	void AdjustCurrentHealth(int h) {
		if(curHealth < 0) {
			curHealth = 0;
			dead = true;
		}
		
		if(curHealth > maxHealth)
			curHealth = maxHealth;
		
		healthBarLength = (Screen.width/2) * (curHealth / (float)maxHealth);
			}
	
	void Dead () {
		if(GUI.Button(new Rect(0,0,100,50), "Dead")){
			}
		}
	}

A easy way for me to explain it, like GTA, Saints Row. Where when the player dies he goes to the Hospital. If i have progression from anywhere i will keep this up to date with what i have done.

Thank You

This might help:

Public float playerMinHealth = 0

If (playerHealth <= playerMinHealth)
{
Transform. Location…//enter co-ordinates here
}

I hope that helps a bit- I am an amateur so I’m sorry if it doesn’t

You need to add a way for the script to be triggered. You can have a collider on your rocket launcher projectile and select “is trigger.” Then add a script to the player prefab:

//UnityScript function OnTriggerEnter( c:Collider){ if(c.gameObject.tag == "projectile"){ //this can be whatever you want, just make sure to set it in the inspector gameObject.SendMessage("AdjustCurrentHealth", -25); //insert proper amount of health to hurt here }
To move the player add this to your health script:
if(dead) transform.position = Vector3(x, y, z); //insert coordinates here

Hi i am complete novice at this kind of scripting and have noticed that my health goes less than 0 when it goes down where it needs to stop at 0 then player dies and respawn on certain location and sorry cmpgk1024 not sure what you mean by (You have too many curly braces. When is Dead() getting called? I would recommend putting the if statement in your update function so you check for death once per frame.) can you explain a little more please.