コード例 #1
0
        /// <summary>
        /// What happens when the object gets picked
        /// </summary>
        protected override void Pick()
        {
            Health characterHealth = _pickingCollider.GetComponent <Health>();

            // else, we give health to the player
            characterHealth.GetHealth(HealthToGive, gameObject);
        }
コード例 #2
0
ファイル: HealthAutoRefill.cs プロジェクト: andres-03/01
        /// <summary>
        /// Tests if a refill is needed and processes it
        /// </summary>
        protected virtual void ProcessRefillHealth()
        {
            if (!RefillHealth)
            {
                return;
            }

            if (Time.time - _lastHitTime < CooldownAfterHit)
            {
                return;
            }

            if (_health.CurrentHealth < _health.MaximumHealth)
            {
                switch (RefillMode)
                {
                case RefillModes.Bursts:
                    if (Time.time - _lastBurstTimestamp > DurationBetweenBursts)
                    {
                        _health.GetHealth(HealthPerBurst, this.gameObject);
                        _lastBurstTimestamp = Time.time;
                    }
                    break;

                case RefillModes.Linear:
                    _healthToGive += HealthPerSecond * Time.deltaTime;
                    if (_healthToGive > 1f)
                    {
                        int givenHealth = (int)_healthToGive;
                        _healthToGive -= givenHealth;
                        _health.GetHealth(givenHealth, this.gameObject);
                    }
                    break;
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// When the item is used, we try to grab our character's Health component, and if it exists, we add our health bonus amount of health
        /// </summary>
        public override void Use()
        {
            base.Use();

            if (TargetInventory.Owner == null)
            {
                return;
            }

            Health characterHealth = TargetInventory.Owner.GetComponent <Health>();

            if (characterHealth != null)
            {
                characterHealth.GetHealth(HealthBonus, TargetInventory.gameObject);
            }
        }