- Home /
Death scene/screen on player Health Script Wont work!
using UnityEngine; using System.Collections;
public class global:MonoBehaviour {
public int currentHealth;
public int maximumHealth = 100;
public float hbLength;
// Use this for initialization
void Start () {
currentHealth = maximumHealth;
hbLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
ChangeHealth(0);
}
void OnGUI () {
GUI.Box (new Rect(10, 10, hbLength, 25), currentHealth + " / " + maximumHealth);
}
public void ChangeHealth (int health) {
currentHealth += health;
hbLength = (Screen.width / 2) * (currentHealth / (float)maximumHealth);
if(currentHealth <= 0)
{
Application.LoadLevel(9);
}
}
} I made this Player Health script with the hope to just add a death scene when my health hits 0 but it wont work the health portion works great it is just that it wont load my level, i am new to unity so any help is very appreciated, thanks.
is the level added to the build scene settings? and is it 9 in the list?
you can use strings to call your level name.
i.e. Application.LoadLevel("Level_1");
Ya I did have it under, I got it firstly from a tutorial that's why I dont understand what I did wrong level 9 and I used that application.loadlevel(9) but it didn't work
Hey GOT IT WOR$$anonymous$$ING!!! ID$$anonymous$$ what was wrong I just played with it forever and it worked, Thank you so much for you reply though