public void GotHit(int damage) { m_healthComponent.ChangeHealth(-damage); UpdateHealthColor(); if (SceneManager.GetActiveScene().name != "TutorialLevel") { //online //socialManager?.UpdateHeavyHitterAchievement(); } if (!m_healthComponent.alive) { //tell the game manager to give gold GameManager.s_instance.GiveGold(20); // destroy if (SceneManager.GetActiveScene().name != "TutorialLevel") { LevelManager.s_instance.DestroyEnemy(id); } else if (SceneManager.GetActiveScene().name == "TutorialLevel") { TutorialManager.s_instance.ResetEnemy(); Destroy(gameObject); } } }
private void AddingResource(GameObject other) { _audioSourcePickup.pitch = Random.Range(0.8f, 1.2f); _audioSourcePickup.Play(); Debug.Log($"AddingResource"); var bonus = other.GetComponentInParent <Bonus>(); switch (bonus.Type) { case TypeAmmunition.Life: GameManager.Instance.LIFE += bonus.Count; break; case TypeAmmunition.Rocket: Ammunitions.CountRockets += bonus.Count; break; case TypeAmmunition.Health: Health.ChangeHealth(+bonus.Count); break; case TypeAmmunition.Coin: GameManager.Instance.ScoreManager.Coins += bonus.Count; break; } Destroy(other); }
private void OnCollisionEnter(Collision other) { if (other.gameObject.tag == "Enemy") { Debug.Log("collide enemy"); if (SceneManager.GetActiveScene().name == "TutorialLevel") { TutorialManager.s_instance.ResetLevel(); } else { m_healthComponent.ChangeHealth(-15f); AdjustHealthWheelValueAndColor(); if (SceneManager.GetActiveScene().name != "TutorialLevel") { //tell the game manager that the tower took damage if (GameManager.s_instance.towerTookDamage == false) { GameManager.s_instance.towerTookDamage = true; Debug.Log("Took damage"); } } } } else if (other.gameObject.tag == "EnemyProjectile") { m_healthComponent.ChangeHealth(-5f); AdjustHealthWheelValueAndColor(); if (SceneManager.GetActiveScene().name != "TutorialLevel") { //tell the game manager that the tower took damage if (tookDamage == false) { tookDamage = true; Debug.Log("Took damage"); } } } }
public void OnCollisionStay2D(Collision2D hit) { if (!useTrigger) { HealthComponent collider = hit.gameObject.GetComponent <HealthComponent>(); // Only do damage if colliding component has a HealthComponent if (collider) { collider.ChangeHealth((int)(-damageRate * Time.deltaTime)); } } }
public void OnCollisionEnter2D(Collision2D hit) { if (!useTrigger) { HealthComponent collider = hit.gameObject.GetComponent <HealthComponent>(); // Only do damage if colliding component has a HealthComponent if (collider) { collider.ChangeHealth(-enterDamage); } } }
private void OnTriggerEnter2D(Collider2D other) { var health = other.GetComponent <HealthComponent>(); if (other.GetComponent <BulletBehaviour>() != null) { return; } if (health != null) { other.GetComponent <HealthComponent>().ChangeHealth(-1); } _health.ChangeHealth(-1); }
public void TakeDamage(DamageDealerComponent damageDealer) { _healthComponent.ChangeHealth(damageDealer.Damage); }