//Collisions private void OnTriggerEnter2D(Collider2D collision) { LaserFire laser = collision.gameObject.GetComponent <LaserFire>(); //Checks if collider is LaserFire object to take damage, if less than heath, destroys. if (laser) { laser.Hit(); health -= laser.GetDamage(); Debug.Log("Player shot!!!"); if (health <= 0) { PlayerDeath(); } } }
//Collisions with this enemy private void OnTriggerEnter2D(Collider2D collision) { //gets reference to LaserFire type object if is collision LaserFire laser = collision.gameObject.GetComponent <LaserFire>(); //if not null object if (laser != null) { //calls Hit() of the laser, gets damage amount and ups the score by enemy scoreValue laser.Hit(); health -= laser.GetDamage(); scoreKeeper.Score(scoreValue); if (health <= 0) { Destroy(gameObject); AudioSource.PlayClipAtPoint(deathSound, transform.position); Debug.Log("destroyed!!!"); } } }