protected void Attack(GameObject enemy) { if (!gameObject.activeSelf) { return; } if (enemy.GetComponent <Rigidbody>()) { Vector3 direction = (enemy.transform.position - transform.position); enemy.GetComponent <Rigidbody>().AddForce(direction.normalized * _forceOnImpact); } // find parent LivingMonoBehavior enemyHealth = enemy.GetComponentInChildren <LivingMonoBehavior>(); if (enemyHealth && !enemyHealth.IsDead) { enemyHealth.DeductHealth(_damageOnHit, _player); } if (_hitPrefab) { GameObject hitObject = (GameObject)Instantiate(_hitPrefab, _hitTransform.position, Quaternion.identity); } PlayAttackSound(_hitTransform.position); }
void OnTriggerEnter(Collider other) { if (other.isTrigger) { return; } LivingMonoBehavior health = other.GetComponent <LivingMonoBehavior>(); if (health) { health.DeductHealth(_damage); } }