Пример #1
0
    /**
     * Called as soon as the fall animation started by an animation event.
     */
    public void OnFallAnimationStarted()
    {
        // A falling player will be moved on a special layer, so that it does not interact with most other objects while
        // falling.
        this.gameObject.layer = LayerMask.NameToLayer("Falling");

        fallingSounds.PlayOneShot();
    }
Пример #2
0
    protected override bool ChangeHealth(int delta, bool playSounds = true)
    {
        // if the player is thrown he shouldn't get any damage
        if (_playerState == PlayerState.thrown)
        {
            return(false);
        }

        _data.HealthPoints += delta;

        // Display some effects when damaged
        if (delta < 0)
        {
            _tintFlashController.FlashTint(UnityEngine.Color.red, TimeInvincible);
            if (playSounds)
            {
                hitSounds.PlayOneShot();
            }
            Input.PlayVibrationFeedback(new List <float>
            {
                200
            });
        }

        if (delta > 0)
        {
            _tintFlashController.FlashTint(UnityEngine.Color.green, 0.5f);
        }

        if (delta != 0)
        {
            DisplayLifeGauge();
        }

        if (_data.HealthPoints <= 0)
        {
            if (playSounds)
            {
                deathSounds.PlayOneShot();
            }

            // If we died, we want to spawn gold on our last position
            var lostGold = Math.Min(goldLossOnDeath, _data.GoldCounter);
            _data.GoldCounter -= lostGold;
            // We want to spawn the gold on the last respawn position
            // This is the last position of the player on solid ground
            var goldSpawnPosition = spawnable.RespawnPosition;
            // spawn the gold
            for (int i = 0; i < lostGold; ++i)
            {
                Instantiate(coinPrefab, goldSpawnPosition, Quaternion.identity);
            }

            spawnable.Respawn(Spawnable.RespawnReason.Death);
        }
        return(true);
    }
Пример #3
0
    /**
     * Plays some effects to give feedback that the enemy has taken damage.
     *
     * Currently, it flashes the enemy red for the duration of its invincibility after being hit.
     * It also plays a hit sound, when present
     */
    private void PlayDamageEffects()
    {
        // Flash enemy red for the duration of its temporary invincibility
        _tintFlashController.FlashTint(
            Color.red, TimeInvincible
            );

        // Play sound
        if (!ReferenceEquals(hitSounds, null))
        {
            hitSounds.PlayOneShot();
        }
    }
Пример #4
0
 private void Attack()
 {
     Animator.SetTrigger(AttackTrigger);
     fightingSounds.PlayOneShot();
 }