//call explosion effect public void GoBoom() { //call explosion Explosion explosion = GetComponent <Explosion>(); explosion.BlowUp(); }
void OnTriggerEnter(Collider collider) { Debug.Log("Laser Bullet hit: " + collider.tag); //make sure tag is not player if (collider.tag != "Player") { //get explosion component and check if it exists Explosion targetExplosion = collider.GetComponent <Explosion>(); //if so invoke the target blow-up routine -TODO handle potential target shields if (targetExplosion != null) { targetExplosion.BlowUp(); } //always destroy bullet Destroy(gameObject); } }
//custom method added to destroy, invoke explosion if detected hit public void DestroyOnHit(GameObject hitObject) { if (hitObject != null) { Debug.Log("Laser Stream Beam hit: " + hitObject.tag); //make sure tag is not player if (hitObject.tag != "Player") { //get explosion component and check if it exists Explosion targetExplosion = hitObject.GetComponent <Explosion>(); //if so invoke the target blow-up routine -TODO handle potential target shields if (targetExplosion != null) { targetExplosion.BlowUp(); } } } }
//method to take damage on shields public void TakeDamage(int damageAmount = 1) { currentHealth -= damageAmount; //check to ensure have current health at least zero if (currentHealth < 0) { currentHealth = 0; } //use events to notify EventManager.HandleDamage(currentHealth / (float)maxHealth); //if health is 0 or lower, invoke blow up on explosion if (currentHealth < 1) { //send event for player death EventManager.PlayerDeath(); //create explosion Explosion explosion = GetComponent <Explosion>(); explosion.BlowUp(); //TODO - remove life from lives } }