public void CallTriggerDamage() { foreach (GameObject obj in triggerList) { WorldItem wi = obj.GetComponent <WorldItem>(); if (obj.GetComponent <Unit>()) { obj.GetComponent <Unit>().DoDamage(gameObject, damageType); } else if (wi != null && wi.isDestroyable) { wi.interact(); } } }
/// <summary> /// Courotine that Handles the Damage after x seconds from the Sword /// </summary> /// <returns></returns> private IEnumerator SwingSwordAttack() { yield return(new WaitForSecondsRealtime(doDamageAfterSec)); removeNullObjectFromHitList(); List <GameObject> remList = new List <GameObject>(); foreach (GameObject obj in hitObjects) { Unit objU = obj.GetComponent <Unit>(); if (objU != null) { if (objU.currentHealth - damageType.damage <= 0) { remList.Add(obj); } // TODO Clean trash code int d = damageType.damage; damageType.damage = d + currentCharges; objU.DoDamage(gameObject, damageType); damageType.damage = d; // End Trash Code } // Interact with Destroyable Item WorldItem wi = obj.GetComponent <WorldItem>(); if (wi != null && wi.isDestroyable) { wi.interact(); } } foreach (GameObject obj in remList) { hitObjects.Remove(obj); } setCharges(0); }
private void OnTriggerEnter(Collider other) { if (other.gameObject != gameObject && other.GetComponent <Room>() == null) { switch (other.tag) { case "Interactable": WorldItem wi = other.GetComponent <WorldItem>(); if (wi != null && wi.isDestroyable && destoryInteractables) { wi.interact(); DestroyProjectile(); } break; case "Player": other.gameObject.GetComponent <Unit>().DoDamage(gameObject, damageType); break; case "Enemy": if (isHittingEnemies) { other.gameObject.GetComponent <Unit>().DoDamage(gameObject, damageType); DestroyProjectile(); } break; case "Weapon": break; case "Projectile": break; default: DestroyProjectile(); break; } } }