public void DamageUnit(int damage) { int damageTaken; damageTaken = CalculateDamage(damage); _isKilled = _myHealth.ChangeHealth(-damageTaken); if (_isKilled) { if (SoundController._instance._soundOn) { _myAudioSource.PlayOneShot(_myDeathClip); } if (!_isDesignerMode) { _myAnimator.SetTrigger("Die"); } else { DeathEnded(); } } else { if (SoundController._instance._soundOn) { _myAudioSource.PlayOneShot(_myDamageClip); } if (!_isDesignerMode) { _myAnimator.SetTrigger("TakeDamage"); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { HealthController playerHpCon = other.gameObject.GetComponent <HealthController>(); if (playerHpCon != null && playerHpCon.timer <= 0) { playerHpCon.ChangeHealth(dmg); if (knockback > 0) { Rigidbody2D player = other.gameObject.GetComponent <Rigidbody2D>(); player.velocity = (player.transform.position - gameObject.transform.position) * (knockback + Random.Range(-knockbackRandomness, knockbackRandomness)); } if (stunLock > 0) { PlayerController pc = other.gameObject.GetComponent <PlayerController>(); if (pc != null) { pc.stunTimer = stunLock; } } Debug.Log("Player Hit"); cam.Shake(0.1f, 0.2f); if (destroyAfter) { DestroyObject(); } } } }
void OnTriggerEnter2D(Collider2D other) { //the Enemys Rigidbodys sleeping mode must be set to never sleep for collisions to take place when the object is stoped... //theres got be be a better way to do this... if (other.tag == "Player" || other.name.Contains("CameraZone") == true || other.tag == "Npc") { return; } cam.Shake(0.1f, 0.2f); HealthController hpController = other.GetComponent <HealthController>(); AnimatorStateInfo stateInfo = playerAnimator.GetCurrentAnimatorStateInfo(0); Rigidbody2D rb = other.GetComponent <Rigidbody2D>(); EnemyMovementManager emm = other.GetComponent <EnemyMovementManager>(); if (stateInfo.fullPathHash == attackHash) { print(name + " hit " + other.name); if (hpController != null && hpController.timer <= 0) { hpController.ChangeHealth(damage); cam.Shake(0.1f, 0.2f); if (rb != null) { rb.velocity = (rb.transform.position - player.transform.position) * knockback; } if (emm != null) { emm.stunTimer = stun; } } } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Enemy") { HealthController enemyHpCon = other.gameObject.GetComponent <HealthController>(); if (enemyHpCon != null && enemyHpCon.timer <= 0) { enemyHpCon.ChangeHealth(dmg); if (knockback > 0) { Rigidbody2D enemy = other.gameObject.GetComponent <Rigidbody2D>(); enemy.velocity = (enemy.transform.position - gameObject.transform.position) * (knockback + Random.Range(-knockbackRandomness, knockbackRandomness)); } if (stunLock > 0) { EnemyMovementManager ec = other.gameObject.GetComponent <EnemyMovementManager>(); if (ec != null) { ec.stunTimer = stunLock; } } Debug.Log("Enemy Hit"); if (destroyAfter) { DestroyObject(); } } } }
IEnumerator DealDamage() { while (true) { yield return(new WaitForSeconds(DamageDelay)); hc.ChangeHealth(-Mathf.Abs(Damage)); } }
bool IDamageReceiver.ApplyDamage(IDamageProvider damageProvider) { if (!enabled) { return(false); } var healthDiff = _healthController.ChangeHealth(-damageProvider.DamageValue); return(healthDiff != 0); }
private void OnTriggerEnter2D(Collider2D collision) { if (!_hasLeftOrigin && collision.gameObject == Origin) return; if (collision.gameObject.CompareTag("Sword")) return; HealthController otherHealthController = collision.gameObject.GetComponent<HealthController>(); if (otherHealthController == null || otherHealthController.IsIntangible) return; otherHealthController?.ChangeHealth(-_damage); Destroy(gameObject); Hit?.Invoke(); }
/// <summary> /// OnTriggerEnter is called when the Collider other enters the trigger. /// </summary> /// <param name="other">The other Collider involved in this collision.</param> void OnTriggerEnter(Collider other) { if (!other.GetComponent <HealthController>()) { return; } if (IgnoredTags.Any(other.tag.Contains)) { return; } print($"Dealing damage to {other.name}"); HealthController health = other.GetComponent <HealthController>(); health.ChangeHealth(-Damage); }
private void Hit(GameObject target) { HealthController healthController = target.GetComponent <HealthController>(); healthController?.ChangeHealth(-_damage); }