/// <summary> /// Iterates through healables and heals them all based on healRate, /// only when t > 1.0f. /// If t is less than 1.0f, /// this function has no effect. /// </summary> private void healHealables() { if (t < 1.0f) { return; } foreach (GameObject g in healables) { HealthBehavior hb = g.GetComponent <HealthBehavior>(); // hb better be valid before we heal it! Assert.IsTrue(hb != null, g.name + " does not have a HealthBehavior script attached"); Assert.IsTrue(hb.isActiveAndEnabled, g.name + "'s HealthBehavior either is inactive or disabled"); hb.adjustHealth(healRate); } }
private void DealDamage() { // Deal damage to all objects that sc touches Collider[] colliders = Physics.OverlapSphere(bullet.transform.position, radius); foreach (Collider c in colliders) { GameObject go = c.gameObject; if (tagManager.isShootable(go.tag)) { HealthBehavior hb = go.GetComponent <HealthBehavior>(); Assert.IsTrue(hb != null, go.name + " does not have a HealthBehavior attached,\n" + "and " + bullet.name + " just tried to deal damage to it"); hb.adjustHealth(-damage); } } }
void OnCollisionEnter(Collision collision) { switch (collision.gameObject.tag) { case "Player1_obj": if (this.gameObject.tag != "P1_Bullet") { collisionHB = collision.gameObject.transform.root.GetComponent <HealthBehavior>(); if (collisionHB) { collisionHB.adjustHealth(-bulletDamage); } } ResetBullet(); break; case "Player2_obj": if (this.gameObject.tag != "P2_Bullet") { collisionHB = collision.gameObject.transform.root.GetComponent <HealthBehavior>(); if (collisionHB) { collisionHB.adjustHealth(-bulletDamage); } } ResetBullet(); break; case "P1_Base": case "P1_Spawner": case "P1_Spawner_Soldier": case "P1_Spawner_Teddy": case "P1_Turret": case "P1_Healer": case "P1_Soldier": case "P1_Teddy": if (this.gameObject.tag != "P1_Bullet") { collisionHB = collision.gameObject.transform.GetComponent <HealthBehavior>(); if (collisionHB) { collisionHB.adjustHealth(-bulletDamage); } } ResetBullet(); break; case "P2_Base": case "P2_Spawner": case "P2_Spawner_Soldier": case "P2_Spawner_Teddy": case "P2_Turret": case "P2_Healer": case "P2_Soldier": case "P2_Teddy": if (this.gameObject.tag != "P2_Bullet") { collisionHB = collision.gameObject.transform.GetComponent <HealthBehavior>(); if (collisionHB) { collisionHB.adjustHealth(-bulletDamage); } } ResetBullet(); break; case "Floor": case "Wall": ResetBullet(); break; default: ResetBullet(); break; } }