changing gui texture colors based on health

I want the players GUI texture to change color based on the players health however since you cannot use operators with int variables since something like the example below doesn’t work I am out of ideas any help would be appreciated thanks again.

Example of what I tried

var healthTex : Texture2D;
var healthMid : Texture2D;

function Update()
if(player health <= 50)
healthTex = health mid;

Never mind I figured it out. I forgot to access my health variable from my other script thanks anyway :wink:

You can have an array of colors and make player’s health int as an index in the array then you can assign the color to material’s main color.


Color[] health_colors = {,, Color.cyan, Color.gray,,, Color.magenta, Color.white, Color.yellow, new Color (255,0,0,255) };    
int player_health = 50; 
int color_index = player_health /10;
renderer.material.color = health_colors [color_index];