Example #1
0
    /// <summary>
    /// The function is generally usesd by other game objects which can damage the player. This function handles various damage types.
    /// Some attacks will have an instant damage on the health while other may have a damage over time.
    /// Each one will damage the player and, if applicable, call the SOEffectHandler to play the appropriate effect.
    /// </summary>
    public void DecrementPlayerHealth(int damage, float duration = 0.0f, DamageEnum damageType = DamageEnum.None)
    {
        if (damageType != DamageEnum.LaserContinuous)
        {
            // Tell the input manager to stop taking in input for 0.5 seconds
            // To ensure there are no conflicting movement requests, clear the player movement queue of all requests.
            if (_inputManager == null)
            {
                _inputManager = InputManager.Instance.GetComponent <InputManager>();
            }
            _inputManager.PauseInput(0.5f);
            _movementManager.ClearQueue();
        }

        // If duration is passed in for damages which last for X amount of time
        if (duration > 0.0f)
        {
            //_damageReceived = damage;
            _duration = duration;

            // For each of the damage effects, call the appropriate functions to give the selected effect.
            if (damageType == DamageEnum.Acid)
            {
                AcidDamageEffect();
                _health -= damage;
                if (_effect != null)
                {
                    _SOEffectHandler.StopEffect(_effect);
                }
                _effect     = _SOEffectHandler.PlayEffect(EffectEnums.AcidDamageEffect, _effectPositions[1].position);
                _damageType = damageType;
            }
            else if (damageType == DamageEnum.Explosion)
            {
                ExplosionDamageEffect();
                if (_effect != null)
                {
                    _SOEffectHandler.StopEffect(_effect);
                }
                _effect     = _SOEffectHandler.PlayEffect(EffectEnums.ExplosionDamageEffect, _effectPositions[1].position);
                _damageType = damageType;
                _health    -= damage;
                _scrnShkRequest.ShakeRequest();
            }

            _timer = Time.time;
        }
        else
        {
            _health -= damage;
            _scrnShkRequest.ShakeRequest();
        }

        // UPDATE HEALTH UI
        if (UpdateHealth != null)
        {
            UpdateHealth(_health);
        }
    }