private void OnTriggerStay2D(Collider2D other) { if (!_hasCollided) { if (other.gameObject.CompareTag("Player") || other.gameObject.CompareTag("Shield")) { bool collidesWithPlayer = other.gameObject.CompareTag("Player"); Player playerScript = collidesWithPlayer ? other.gameObject.GetComponent <Player>() : other.gameObject.GetComponentInParent <Player>(); if (!playerScript.IsDead) { bool gotPickedUp = true; switch (PowerupType) { case PowerupType.PtHealth: playerScript.TriggerHealthPickup(); break; case PowerupType.PtSpeedup: playerScript.TriggerAmmoPickup(GunType.GtSpeedUp, PowerupType); break; case PowerupType.PtResearch: playerScript.TriggerResearchPickup(); break; case PowerupType.PtShield: playerScript.TriggerShieldPickup(); break; case PowerupType.PtTeleport: playerScript.TriggerAmmoPickup(GunType.GtTeleport, PowerupType); break; case PowerupType.PtBomb: gotPickedUp = collidesWithPlayer ? playerScript.PlayerGotHit() : playerScript.ShieldGotHit(); if (gotPickedUp) { EventLogger.PrintToLog(collidesWithPlayer ? "Bomb Collides v Player" : "Bomb Collides v Shield"); } break; } if (gotPickedUp) { _hasCollided = true; _basicObjectScript.OnDestruction(); Destroy(gameObject); } } } } }
private void Explode() { if (_assignedEnemyWave != null) { _assignedEnemyWave.OnEnemyCountChanged(); } if (_playerScript) { //player might not be alive, game might have ended, do not score negative points in this case _playerScript.TriggerEnemyDestruction(); } _hasCollided = true; _basicObjectScript.OnDestruction(); Destroy(gameObject); }
public bool PlayerGotHit() { if (_isInvulnerable || IsDead || PlayerHealth == 0) { // bullet goes right through player return(false); } if (_inTutorial) { _spawnManagerScript.TutorialOnPlayerDeath(); } if (_losesHealth) { --PlayerHealth; _statsManagerScript.HealthChangeCoroutine(-1); } if (PlayerHealth == 0) { EventLogger.PrintToLog("Player Dies: Game Over"); _endGameScoreText.SetTextVisible(); Destroy(gameObject); } else { EventLogger.PrintToLog("Player Loses Health"); if (IsShielded) { //shield also disappears ShieldGotHit(); } _deathTime = Time.time; IsDead = true; _spriteRenderer.enabled = false; SetChildRenderers(false); } _basicObjectScript.OnDestruction(); return(true); }