void ApplyDamageToHealth(GameObject collidedObject) { HealthComponent health = collidedObject.GetComponent <HealthComponent>(); if (health != null) { health.ApplyDamage(Damage); } }
public static void DealDamage(GameObject DamagedObject, int Damage) { HealthComponent health = DamagedObject.GetComponent <HealthComponent>(); if (health) { health.ApplyDamage(Damage); } }
public void ApplyDamageToHealth(GameObject otherObject) { HealthComponent health = otherObject.GetComponent <HealthComponent>(); if (health != null) { health.ApplyDamage(damage); } }
//// NO UPDATE //private void Update() //{ //} public void TriggerAttack() { if ((Time.time - lastAttackTime) < AttackCooldownTime) { return; } Ray ray = new Ray { origin = FirePoint.position, direction = FirePoint.forward, }; if (Physics.Raycast(ray, out RaycastHit raycastHit, Range, HitMask)) { HealthComponent hitObject = raycastHit.collider.transform.root.GetComponent <HealthComponent>(); //HealthComponent hitObject = raycastHit.collider.GetComponentInParent<HealthComponent>(); // can also do this if (hitObject != null) { Debug.DrawLine(ray.origin, raycastHit.point, Color.red, 0.5f); hitObject.ApplyDamage(Damage); } }
protected void ApplyDamage(HealthComponent healthComponent) { healthComponent.ApplyDamage(DamagePerHit); }