So I have this script attatched to an invisible cube with a box collider that is a trigger attatched to my player...
public var healthamt : float;
var tex1 : Texture;
private var attacked : boolean;
function OnTriggerEnter(Col : Collider){
if (Col.gameObject.tag == "enemy"){
attacked = true;
}
}
function Update(){
if (attacked){
healthamt -= Time.deltaTime;
}
if (healthamt > 100){
healthamt = 100;
}
}
function OnGUI(){
GUI.color = new Color32(255, 255, 255, 100 - healthamt);
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), tex1);
}
But when my enemy enters the collider it doesn't change my healthamt variable at all.
Why, god?
Why?
↧