/// <summary> /// On update, makes our bomb flicker, activates the damage area and destroys the bomb if needed /// </summary> protected virtual void Update() { _timeSinceStart += Time.deltaTime; // flickering if (_timeSinceStart >= TimeBeforeFlicker) { if (!_flickering && FlickerSprite) { // We make the bomb's sprite flicker if (_renderer != null) { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickerColor, 0.05f, (TimeBeforeExplosion - TimeBeforeFlicker))); } } } // activate damage area if (_timeSinceStart >= TimeBeforeExplosion && !_damageAreaActive) { EnableDamageArea(); _renderer.enabled = false; InstantiateExplosionEffect(); PlayExplosionSound(); _damageAreaActive = true; } if (_timeSinceStart >= TimeBeforeExplosion + DamageAreaActiveDuration) { DestroyBomb(); } }
/// public override void PerformAction() { if (_renderer != null) { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickerColor, _flickerSpeed, flickerDuration)); } }
/// <summary> /// Called when the player takes damage /// </summary> /// <param name="damage">The damage applied.</param> /// <param name="instigator">The damage instigator.</param> public override void Damage(int damage, GameObject instigator, float flickerDuration, float invincibilityDuration) { // When the character takes damage, we create an auto destroy hurt particle system if (DamageEffect != null) { Instantiate(DamageEffect, transform.position, transform.rotation); } if (transform.localScale.y == _initialScale.y) { LevelManager.Instance.KillPlayer(_character); } else { // we prevent the character from colliding with layer 12 (Projectiles) and 13 (Enemies) DamageDisabled(); StartCoroutine(DamageEnabled(0.5f)); Shrink(2f); // We make the character's sprite flicker if (GetComponent <Renderer>() != null) { Color flickerColor = new Color32(255, 20, 20, 255); StartCoroutine(MMImage.Flicker(_renderer, _initialColor, flickerColor, 0.05f, 0.5f)); } } }
protected virtual void Update() { HandleInput(); _timeSinceStart += Time.deltaTime; // flickering if (_timeSinceStart >= TimeBeforeFlicker) { if (!_flickering && FlickerSprite) { // We make the bomb's sprite flicker if (_renderer != null) { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickerColor, 0.05f, (TimeBeforeExplosion - TimeBeforeFlicker))); } } } // activate damage area on input if (_timeSinceStart >= TimeBeforeExplosion && !_damageAreaActive) { StartCoroutine(BlowUp()); } }
/// <summary> /// Called when the object takes damage /// </summary> /// <param name="damage">The amount of health points that will get lost.</param> /// <param name="instigator">The object that caused the damage.</param> /// <param name="flickerDuration">The time (in seconds) the object should flicker after taking the damage.</param> /// <param name="invincibilityDuration">The duration of the short invincibility following the hit.</param> public virtual void Damage(int damage, GameObject instigator, float flickerDuration, float invincibilityDuration) { // if the object is invulnerable, we do nothing and exit if (Invulnerable) { return; } // if we're already below zero, we do nothing and exit if ((CurrentHealth <= 0) && (InitialHealth != 0)) { return; } // we decrease the character's health by the damage float previousHealth = CurrentHealth; CurrentHealth -= damage; if (OnHit != null) { OnHit(); } if (CurrentHealth < 0) { CurrentHealth = 0; } // we prevent the character from colliding with Projectiles, Player and Enemies if (invincibilityDuration > 0) { DamageDisabled(); StartCoroutine(DamageEnabled(invincibilityDuration)); } // we trigger a damage taken event MMDamageTakenEvent.Trigger(_character, instigator, CurrentHealth, damage, previousHealth); if (_animator != null) { _animator.SetTrigger("Damage"); } // we play the sound the player makes when it gets hit PlayHitSfx(); // When the character takes damage, we create an auto destroy hurt particle system if (DamageEffect != null) { Instantiate(DamageEffect, transform.position, transform.rotation); } if (FlickerSpriteOnHit) { // We make the character's sprite flicker if (_renderer != null) { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickerColor, 0.05f, flickerDuration)); } } // we update the health bar UpdateHealthBar(true); // if health has reached zero if (CurrentHealth <= 0) { // we set its health to zero (useful for the healthbar) CurrentHealth = 0; if (_character != null) { if (_character.CharacterType == Character.CharacterTypes.Player) { LevelManager.Instance.KillPlayer(_character); return; } } Kill(); } }
protected void Flicker() { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickerColor, 0.05f, 3f)); }
/// <summary> /// Called when the object takes damage /// </summary> /// <param name="damage">The amount of health points that will get lost.</param> /// <param name="instigator">The object that caused the damage.</param> /// <param name="flickerDuration">The time (in seconds) the object should flicker after taking the damage.</param> /// <param name="invincibilityDuration">The duration of the short invincibility following the hit.</param> public virtual void Damage(int damage, GameObject instigator, float flickerDuration, float invincibilityDuration) { if (damage <= 0) { OnHitZero?.Invoke(); return; } // if the object is invulnerable, we do nothing and exit if (TemporaryInvulnerable || Invulnerable) { OnHitZero?.Invoke(); return; } // if we're already below zero, we do nothing and exit if ((CurrentHealth <= 0) && (InitialHealth != 0)) { return; } // we decrease the character's health by the damage float previousHealth = CurrentHealth; CurrentHealth -= damage; OnHit?.Invoke(); if (CurrentHealth < 0) { CurrentHealth = 0; } // we prevent the character from colliding with Projectiles, Player and Enemies if (invincibilityDuration > 0) { DamageDisabled(); StartCoroutine(DamageEnabled(invincibilityDuration)); } // we trigger a damage taken event MMDamageTakenEvent.Trigger(_character, instigator, CurrentHealth, damage, previousHealth); if (_animator != null) { _animator.SetTrigger("Damage"); } // we play the damage feedback DamageFeedbacks?.PlayFeedbacks(); if (FlickerSpriteOnHit) { // We make the character's sprite flicker if (_renderer != null) { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, FlickerColor, 0.05f, flickerDuration)); } } // we update the health bar UpdateHealthBar(true); // if health has reached zero if (CurrentHealth <= 0) { // we set its health to zero (useful for the healthbar) CurrentHealth = 0; if (_character != null) { if (_character.CharacterType == Character.CharacterTypes.Player) { LevelManager.Instance.KillPlayer(_character); return; } } Kill(); } }
/// <summary> /// Called when the object takes damage /// </summary> /// <param name="damage">The amount of health points that will get lost.</param> /// <param name="instigator">The object that caused the damage.</param> /// <param name="flickerDuration">The time (in seconds) the object should flicker after taking the damage.</param> /// <param name="invincibilityDuration">The duration of the short invincibility following the hit.</param> public override void Damage(int damage, GameObject instigator, float flickerDuration, float invincibilityDuration) { // if the object is invulnerable, we do nothing and exit if (Invulnerable) { return; } // if we're already below zero, we do nothing and exit if ((CurrentHealth <= 0) && (InitialHealth != 0)) { return; } if (ElectricalEffect != null) { StartCoroutine(PlayElectricalEffect()); } // if the Super Suit is aquired, the damage variable is reduced. if (_superSuitAcquired == true) { _reducedDamage = (damage * _superSuitDefenseMultiplier); damage = Mathf.FloorToInt(_reducedDamage); } // if the Super Suit is aquired, the damage variable is reduced. if (_ultraSuitAcquired == true) { _reducedDamage = (damage * _ultraSuitDefenseMultiplier); damage = Mathf.FloorToInt(_reducedDamage); } // we decrease the character's health by the damage float previousHealth = CurrentHealth; CurrentHealth -= damage; // we prevent the character from colliding with Projectiles, Player and Enemies if (invincibilityDuration > 0) { DamageDisabled(); StartCoroutine(DamageEnabled(invincibilityDuration)); } // we trigger a damage taken event MMEventManager.TriggerEvent(new MMDamageTakenEvent(_character, instigator, CurrentHealth, damage, previousHealth)); if (_animator != null) { _animator.SetTrigger("Damage"); } // we play the sound the player makes when it gets hit PlayHitSfx(); // When the character takes damage, we create an auto destroy hurt particle system if (DamageEffect != null) { Instantiate(DamageEffect, transform.position, transform.rotation); } if (FlickerSpriteOnHit) { // We make the character's sprite flicker if (_renderer != null) { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickeringColor, 0.03f, flickerDuration)); } ResetSpriteColor(); } // we update the health bar UpdateHealthBar(true); //NEW CODE for health counter UpdateHealthCounter(CurrentHealth); // if health has reached zero if (CurrentHealth <= 0) { // we set its health to zero (useful for the healthbar) CurrentHealth = 0; if (_character != null) { if (_character.CharacterType == Character.CharacterTypes.Player) { LevelManager.Instance.KillPlayer(_character); return; } } Kill(); BackgroundMusic.Instance.PlayChillRoomMusic(); } }
protected void FlickerOnDeath() { StartCoroutine(MMImage.Flicker(_renderer, _initialColor, _flickerColor, 0.05f, DelayBeforeDestruction)); }