Hi everyone, I have a script here that is supposed to regenerate my shields if the curShield is less than maxShield. It works but it only calls the AdjustCurrentShield function when I am moving, it wont work if I am just standing still. Can someone take a look and tell me where I went wrong?
static var maxHealth : int = 100;
static var curHealth : int = 100;
static var curShield : int = 100;
static var maxShield : int = 100;
static var adjs : int;
static var adj : int;
var shieldText : Texture2D;
var healthText : Texture2D;
var healthBarLength : float;
var shieldBarLength : float;
var shieldRegen : float = 5;
// Use this for initialization
function Start() {
healthBarLength = 250;
shieldBarLength = 250;
}
// Update is called once per frame
function Update() {
AdjustCurrentShield();
AdjustCurrentHealth();
}
function OnGUI() {
GUI.DrawTexture(new Rect(10, 10, shieldBarLength, 24), shieldText);
GUI.DrawTexture(new Rect(10, 36, healthBarLength, 24), healthText);
}
function AdjustCurrentHealth() {
curHealth += adj;
if(curHealth <= 0)
Destroy(gameObject);
if(curHealth > maxHealth)
curHealth = maxHealth;
healthBarLength = 400 * curHealth / maxHealth;
}
function AdjustCurrentShield() {
curShield += shieldRegen * Time.deltaTime;
if(curShield < maxShield)
curShield += shieldRegen * Time.deltaTime;
if(curShield > maxShield)
curShield = maxShield;
if(maxShield < 1)
maxShield = 1;
shieldBarLength = 400 * curShield / maxShield;
}