void OnTriggerEnter(Collider obstacle) { if (obstacle.CompareTag("projectile")) { try { ProjectileBehaviour projectile = obstacle.transform.GetComponent <ProjectileBehaviour>(); TakeHit(projectile); projectile.Die(); } catch { } } if (obstacle.CompareTag("explosion")) { try { Explosion explosion = obstacle.transform.GetComponentInParent <Explosion>(); TakeExplosion(explosion); } catch { monsterExplosion explosion = obstacle.transform.GetComponentInParent <monsterExplosion>(); TakeExplosion(explosion); } } }
void OnTriggerEnter(Collider obstacle) { if ( (!obstacle.CompareTag("Player")) && (!obstacle.CompareTag("Enemy")) && (!obstacle.CompareTag("explosion")) && (!obstacle.CompareTag("projectile")) && (!obstacle.CompareTag("ground")) && (!obstacle.CompareTag("pickup")) ) { obstacleList.Add(obstacle); } if (obstacle.CompareTag("projectile")) { try { ProjectileBehaviour projectile = obstacle.transform.GetComponent <ProjectileBehaviour>(); TakeHit(projectile); projectile.Die(); } catch { EnemyProjectile projectile = obstacle.transform.GetComponent <EnemyProjectile>(); projectile.collided = true; } } if (obstacle.CompareTag("explosion")) { try { Explosion explosion = obstacle.transform.GetComponentInParent <Explosion>(); TakeExplosion(explosion); } catch { monsterExplosion explosion = obstacle.transform.GetComponentInParent <monsterExplosion>(); TakeExplosion(explosion); } } }
public void TakeExplosion(monsterExplosion explosion) { health = health - explosion.damage; }