/// <summary>
        /// On Start, creates or sets the health bar up
        /// </summary>
        protected virtual void Start()
        {
            if (HealthBarType == HealthBarTypes.Prefab)
            {
                if (HealthBarPrefab == null)
                {
                    Debug.LogWarning(this.name + " : the HealthBar has no prefab associated to it, nothing will be displayed.");
                    return;
                }
                _progressBar = Instantiate(HealthBarPrefab, transform.position + HealthBarOffset, transform.rotation) as MMProgressBar;
                _progressBar.transform.SetParent(this.transform);
                _progressBar.gameObject.name = "HealthBar";
            }

            if (HealthBarType == HealthBarTypes.Drawn)
            {
                DrawHealthBar();
                UpdateDrawnColors();
            }

            if (!AlwaysVisible)
            {
                _progressBar.gameObject.SetActive(false);
            }

            if (_progressBar != null)
            {
                _progressBar.UpdateBar(100f, 0f, 100f);
            }
        }
 protected virtual void Update()
 {
     if (TestMode == TestModes.Permanent)
     {
         _progressBar.UpdateBar(CurrentValue, MinValue, MaxValue);
         CurrentValue += Speed * Time.deltaTime * _direction;
         if ((CurrentValue <= MinValue) || (CurrentValue >= MaxValue))
         {
             _direction *= -1;
         }
     }
 }
示例#3
0
        /// <summary>
        /// Updates the bar
        /// </summary>
        /// <param name="currentHealth">Current health.</param>
        /// <param name="minHealth">Minimum health.</param>
        /// <param name="maxHealth">Max health.</param>
        /// <param name="show">Whether or not we should show the bar.</param>
        public virtual void UpdateBar(float currentHealth, float minHealth, float maxHealth, bool show)
        {
            // if the healthbar isn't supposed to be always displayed, we turn it on for the specified duration
            if (!AlwaysVisible && show)
            {
                _showBar           = true;
                _lastShowTimestamp = (TimeScale == TimeScales.UnscaledTime) ? Time.unscaledTime : Time.time;
            }

            if (_progressBar != null)
            {
                _progressBar.UpdateBar(currentHealth, minHealth, maxHealth);

                if (HideBarAtZero && _progressBar.BarTarget <= 0)
                {
                    StartCoroutine(FinalHideBar());
                }

                if (BumpScaleOnChange)
                {
                    _progressBar.Bump();
                }
            }
        }