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