void OnCollisionEnter2D(Collision2D other) { Enemy enemy = other.collider.GetComponent <Enemy>(); EnemyShipType1 ship2 = other.collider.GetComponent <EnemyShipType1>(); EnemyPlane_01 plane1 = other.collider.GetComponent <EnemyPlane_01>(); EnemyPlane_02 plane2 = other.collider.GetComponent <EnemyPlane_02>(); EnemyBoss plane3 = other.collider.GetComponent <EnemyBoss>(); if (enemy != null) { enemy.ChangeHealth(hurt); Debug.Log("enemy health" + enemy.health); } if (ship2 != null) { ship2.ChangeHealth(hurt); Debug.Log("ship2 health" + ship2.health); } if (plane1 != null) { plane1.ChangeHealth(hurt); } if (plane2 != null) { plane2.ChangeHealth(hurt); } if (plane3 != null) { plane3.ChangeHealth(hurt); } animator.SetBool("ishit", true); rigidbody2d.simulated = false; timer = 0.5f; }
void OnTriggerStay2D(Collider2D other) { Enemy enemy = other.GetComponent <Enemy>(); EnemyShipType1 ship2 = other.GetComponent <EnemyShipType1>(); EnemyPlane_01 plane1 = other.GetComponent <EnemyPlane_01>(); EnemyBoss boss = other.GetComponent <EnemyBoss>(); EnemyPlane_02 plane2 = other.GetComponent <EnemyPlane_02>(); if (enemy != null) { enemy.ChangeHealth(hurt); } if (ship2 != null) { ship2.ChangeHealth(hurt); } if (plane1 != null) { plane1.ChangeHealth(hurt); } if (plane2 != null) { plane2.ChangeHealth(hurt); } if (boss != null) { boss.ChangeHealth(hurt); } }