Healthbar Color change movement

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);
}
}
}

Hello,
for the color part GUI.Box doesn’t use a color but rather a texture, also healthBarLenght is a float so you can’t change a color using that float.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

    GUIStyle style = new GUIStyle();
    Texture2D texture;
    Color redColor = Color.red;
    Color greenColor = Color.green;

    public int curHealth = 100;

    void Start()
    {
        texture = new Texture2D(1, 1);
        texture.SetPixel(1, 1, greenColor);
    }

    private void Update()
    {

        if (curHealth > 50)
        {
            texture.SetPixel(1, 1, greenColor);
        }

        if (curHealth < 50)
        {
            texture.SetPixel(1, 1, redColor);
        }
    }

    public void OnGUI()
    {

        texture.Apply();

        style.normal.background = texture;
        GUI.Box(new Rect(100, 200, 100, 100), new GUIContent(""), style);
    }
}

Here’s a simple script that creates a texture and then draws a GUI.Box which can change color depending upon “curHealth” that you can take apart and put into your own script.

Good luck!