- Home /
How do I stop a GUIBox from being created on top of another GUIBox when a variable inside it has a value removed?
Whenever a variable inside my GUI.Box has something subtracted from it, a new GUI.Box is created under the original, with the new value, how do i make it so that the variable inside the initial box changes? My code is below.
pragma strict
ar playerHealth : int; var playerCurrentHealth : System.String; var damageTaken : float; public var tookDamage : boolean; public var allowMovement : boolean = true; var isDead : boolean; var consumableSelected : boolean;
function Start () { consumableSelected = true; playerHealth = 100; damageTaken = 0; tookDamage = false; allowMovement = true; isDead = false; }
function Update () {
if(tookDamage){
playerHealth = playerHealth - damageTaken;
tookDamage = false;
WaitForSeconds(1);
}
if(playerHealth < 0 ){
allowMovement = false;
isDead = true;
} else if (playerHealth == 0){
allowMovement = false;
isDead = true;
} else {
allowMovement = true;
isDead = false;
}
if(isDead){
rigidbody.constraints = RigidbodyConstraints.None;
}
if(consumableSelected) {
if(Input.GetMouseButtonDown(1)){
playerHealth = playerHealth + 25;
}
}
}
function OnTriggerEnter (c : Collider) { if (c.CompareTag("box o pain")) { tookDamage = true; damageTaken = 20; } }
function OnGUI () { GUI.Box (Rect (20, 10, 100, 20), "Health = " + playerHealth);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613090353im_/https://answers.unity.com/themes/thub/images/avi.jpg)