private void OnCollisionEnter(Collision collision) { HealthScript health = collision.gameObject.GetComponent <HealthScript>(); if (health) { health.ApplyDamage(damageAmount); } }
// Following function applies damages to the player`s health and manages gameOver state if no health is left public void DamagePlayersHealth(int damage) { // Applying damage to the player and getting a boolean to see if the player has no health left bool IsOutOfHealth = playerHealth.ApplyDamage(damage); //If the player is out of health, the GameOver function is called if (IsOutOfHealth) { GameOver(false); } // Calling above function to decrement thenumber of EnemyShips to defeat DecrementEnemyShipNumber(); }
public void healthChange() { if (shield > 1) { shieldDamage(100); Debug.Log("shield damage"); } else if (health > 0) { healthScript.ApplyDamage(500); Debug.Log("health damage"); } }
void attack() { if (attack_timer >= 0) { attack_timer -= Time.deltaTime; } else { Debug.Log("attack1"); GetComponent <Animation>().CrossFade("attack1"); GetComponent <AudioSource>().Play(); attack_timer = 1.5f; health.ApplyDamage(11); } }
void OnTriggerEnter(Collider item) { if (item.tag == "Asteroid") // if the gameobject name is _astriod//using tags is better marcus-15/06/2015 { anim.SetBool("Idel", false); anim.SetTrigger("Impact"); //set of the Impact anim on collision with asteroid - marcus - 15/06/2015 //doDamage(); health.ApplyDamage(asteroidDamage); Invoke("startAnimation", 1.5f); // Debug.Log(health.GetHealth); if (health.GetHealth() <= 0) // if the health is 0 { Debug.Log("Game Over"); } } //Had to comment this section out has it dose nothing at the moment are you working on this // cause at the moment there is no health variable to refrence // I changed all the PickUps variables to pickups to match the varible I created -Marcus: 09/06/15 }