//Health functions public void ChangeHealth(int val) { //Changes health, clamps it from 0 to maxvalue if (m_CurHealth > 0 && m_CurHealth <= m_MaxHealth) { m_IsDamaged = true; m_Renderer.color = Color.red; int temp = m_CurHealth + val; bool lost = false; if (temp < m_CurHealth) { lost = true; } //If entity took damage and cantakedamage is true, change health if (lost && m_CanTakeDamage) { m_CurHealth += val; if (m_Healthbar) { m_Healthbar.ChangeScale(val); } } //If value was positive, add health else if (!lost) { m_CurHealth += val; if (m_Healthbar) { m_Healthbar.ChangeScale(val); } } //Clamp health m_CurHealth = Mathf.Clamp(m_CurHealth, 0, GetMaxHealth()); //What happens when player dies if (m_CurHealth < 1 && GetCanDie()) { if (gameObject.tag == "Player") { Debug.Log("Player is dead!"); } } //Debug.Log("Entity " + gameObject.name + " has " + m_CurHealth + " health left"); } }
public override void Start() { base.Start(); m_CurReload = m_ReloadTime; m_CurAmmo = m_Ammo; m_CurFire = m_FireRate; m_AmmoBar = GetComponentInChildren <Healthbar>(); m_AmmoBar.ChangeScaleFactor(m_Ammo); m_AmmoBar.ChangeScale(m_CurAmmo); m_AmmoBar.gameObject.SetActive(false); }
public override void Attack() { if (!m_IsReloading) { m_AmmoBar.gameObject.SetActive(true); if (m_CurFire >= m_FireRate && m_CurAmmo > 0) { Shoot(); m_TimeSinceLast = 0.0f; m_CurAmmo--; m_CurFire = 0.0f; m_AmmoBar.ChangeScale(-1); } } }
public virtual void ChargeUpdate(bool trueState, float maxValue) { //Activates and sets scale on chargebar if truestate is set if (m_Chargebar) { if (trueState) { m_Chargebar.gameObject.SetActive(true); m_Chargebar.ChangeScale(Time.deltaTime / maxValue); m_CurCharge += Time.deltaTime; m_CurCharge = Mathf.Clamp(m_CurCharge, 0.0f, maxValue); m_IsCharging = true; } else { m_IsCharging = false; m_CurCharge = 0.0f; m_Chargebar.SetScale(0); m_Chargebar.gameObject.SetActive(false); } } }