Life.applyVariation C# (CSharp) Method

applyVariation() public method

public applyVariation ( ) : void
return void
	public void applyVariation()
	{
		_life += _variation;
		if(_life  <= 0f || _suddenDeath) _life = 0f;
		else if(_life  >= _lifeMax) _life = _lifeMax;


		ResetVariation();
	}

Usage Example

Example #1
0
    void Update()
    {
        if (!_pause)
        {
            _lifeManager.regen(Time.deltaTime);
            _energy = _medium.getEnergy() / _maxMediumEnergy;

            if (GameStateController.isShortcutKey(_keyLife, true))
            {
                _lifeManager.addVariation(1f);
            }
            if (GameStateController.isShortcutKey(_keyEnergy, true))
            {
                setEnergy(1f);
            }

            // dammage in case of low energy
            if (_energy <= 0.05f)
            {
                _lifeManager.addVariation(-Time.deltaTime * _lowEnergyDpt);
            }


            // Life animation when life is reducing
            if (_lifeManager.getVariation() < 0)
            {
                if (lifeAnimation.isPlaying == false)
                {
                    lifeAnimation.Play();
                }
            }

            // Energy animation when energy is reducing
            if (_energy < _energyBefore)
            {
                DisplayEnergyAnimation();
            }
            _energyBefore = _energy;


            _lifeManager.applyVariation();
            if (_lifeManager.getLife() == 0f && (_isAlive))
            {
                _isAlive = false;

                RedMetricsManager.get().sendEvent(TrackingEvent.DEATH, null, getLastCheckpointName());
                StartCoroutine(RespawnCoroutine());
            }
        }
    }