public int score; //score of destroy the hazard //========================================================================================================================== void OnTriggerEnter(Collider other) { if (other.tag == "bolt") // player when hit the rock by bolt { Destroy(gameObject); //destroy the rock Destroy(other.gameObject); //destroy the bolt control.UpdateScore(score); // control this is calling from gamecontroller the updating the score when destroy rocks Instantiate(explosion, transform.position, transform.rotation); //make the animation of explosion appear in the sameplace of the player position } else if (other.tag == "Player" && (control.health - control.hazards.asteroidsDamage[0]) <= 0) //if the rock hit the player and can destroy him { Destroy(gameObject); Destroy(other.gameObject); Instantiate(playerExplosion, other.transform.position, other.transform.rotation); control.decreaseHealth(score); control.loseWindow(); } else if (other.tag == "Player") //if the rock hit the player but can't destroy him { Destroy(gameObject); Instantiate(explosion, transform.position, transform.rotation); control.health = control.health - control.hazards.asteroidsDamage[0]; control.decreaseHealth(score); control.UpdateScore(score); if (PowerUps.powerUpCounter > 0) { PowerUps.powerUpCounter--; } } }
//=========================================================================================================================================== void OnTriggerEnter(Collider other) { if (other.tag == "Player") // if player hit enemy { Destroy(gameObject); // destroy enemy Destroy(other.gameObject); // destroy player controller.enemies.enemiesDestroid++; //increase the number of enemies that destroyed because we need to handle it with power up controller.UpdateScore(score); // update new score Instantiate(playerExplosion, other.transform.position, other.transform.rotation); //explosion appear controller.decreaseHealth(100); controller.loseWindow(); //player lose } else if (other.tag == "bolt") { // if bullet hit enemy Destroy(other.gameObject); // destroy bullet numberOfHits++; //increase the hits by bullet if (numberOfHits == MaxnumberOfHits) { Destroy(gameObject); controller.UpdateScore(score); //update score controller.enemies.enemiesDestroid++; //increase the number of enemies that destroyed because we need to handle it with power up Instantiate(explosion, transform.position, transform.rotation); //explosion appear } } }