private void Shoot() { // raycast, stop here if missed. if (!Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit)) { return; } // For every component with iDamageable interface, call TakeDamage() MonoBehaviour[] list = hit.transform.gameObject.GetComponentsInChildren <MonoBehaviour>(); foreach (var mb in list) { if (mb is iDamageable) { iDamageable temp = mb as iDamageable; temp.TakeDamage(damage, cam.transform.forward); } } }
/// <summary> /// Invokes the TakeDamage function from the current target of the instance /// </summary> public void DoDamage() { Target.TakeDamage(Strength); }