I’m trying to make my Healthbar cahnge color at a point and make my healthbar get falldamage but I keep getting script errors. The falldamage is supposed to come on collision, but it won’t. Here the new the script:
using UnityEngine;
using System.Collections;
public class PlayerHealthBar : MonoBehaviour {
GUIStyle style = new GUIStyle();
Texture2D texture;
Color redColor = Color.red;
Color greenColor = Color.green;
public int curHealth = 100;
public int maxHealth = 100;
void Start()
{
texture = new Texture2D(1, 1);
texture.SetPixel(1, 1, greenColor);
}
void Update()
{
AddjustCurrentHealth(0);
}
public void AddjustCurrentHealth(int adj) {
curHealth += adj;
if(curHealth < 0)
{
curHealth = 0;
}
if(curHealth > maxHealth)
{
curHealth = maxHealth;
}
if(maxHealth < 1)
{
maxHealth = 1;
}
if (curHealth > 50)
{
texture.SetPixel(1, 1, greenColor);
}
if(curHealth < 10)
{
Application.LoadLevel (“death”);
}
if (curHealth < 50)
{
texture.SetPixel(1, 1, redColor);
}
}
public void OnGUI()
{
texture.Apply();
style.normal.background = texture;
GUI.Box(new Rect(10, 10, 1000, 20), new GUIContent(“”), style);
if (curHealth - 10) {
GUI.Box(new Rect(10, 10, 1000-100, 20), new GUIContent(“”), style);
}else {
GUI.Box(new Rect(10, 10, 1000+10, 20), new GUIContent(“”), style);
}
}
}