// Update is called once per frame void OnTriggerEnter(Collider other) { HealthBehavior health = other.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(Damage); } }
private void OnTriggerEnter(Collider other) { Destroy(other.gameObject); HealthBehavior health = _player.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(1); } }
private void OnTriggerEnter(Collider enemy) { //Get the health behavior attached to the object HealthBehavior health = enemy.GetComponent <HealthBehavior>(); //If the health value is not null, deal damage if (health) { health.TakeDamage(Damage); } }
//When the other game objects collide private void OnTriggerEnter(Collider other) { //If the other game object was tagged as "Enemy" if (other.CompareTag("Enemy") == true) { //Destroy the other gameObject Destroy(other.gameObject); //Tell the player to takeDamage _playerHealth.TakeDamage(1); FindObjectOfType <AudioManager>().Play("PlayerHurt"); } }
//What happens when the object touches the player private void OnCollisionEnter(Collision other) { if (!other.gameObject != _movement.gameObject) { return; } HealthBehavior health = other.gameObject.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(_damage); } }
private void OnTriggerEnter(Collider other) { HealthBehavior otherHealth = other.GetComponent <HealthBehavior>(); if (otherHealth == null) { Destroy(gameObject); } else { otherHealth.TakeDamage(_damage); } }
//COMPLETE WHEN HEALTHBEHAVIOUR IS DONE private void OnTriggerEnter(Collider other) { //Create a HealthBehaviour variable and set it equal to the health of what the bullet collides with HealthBehavior health = other.GetComponent <HealthBehavior>(); //check owner on collision before dealing damage if (other.gameObject != Owner) { //If the bullet collides with something that has health, call TakeDamage if (health) { health.TakeDamage(Damage); } } }
private void OnCollisionEnter(Collision collision) { //If the collided object isn't the target, return if (collision.gameObject != _movement.target) { return; } HealthBehavior health = collision.gameObject.GetComponent <HealthBehavior>(); if (health) { health.TakeDamage(_damage); } }