Exemplo n.º 1
0
 private void Awake()
 {
     _actor        = GetComponent <Actor>();
     _brain        = GetComponent <FighterBrain>();
     _stamina      = GetComponent <CharacterStamina>();
     _obstacle     = GetComponent <NavMeshObstacle>();
     _direction    = transform.forward;
     _lastPosition = transform.position;
 }
Exemplo n.º 2
0
        private void LateUpdate()
        {
            if (Target != _cachedTarget)
            {
                _cachedTarget = Target;

                if (Target != null)
                {
                    _cachedCharacterStamina = Target.GetComponent <CharacterStamina>();
                    _cachedCharacterName    = Target.GetComponent <CharacterName>();
                }
                else
                {
                    _cachedCharacterStamina = null;
                    _cachedCharacterName    = null;
                }
            }

            if (_cachedCharacterStamina != null)
            {
                Value = _cachedCharacterStamina.Stamina / _cachedCharacterStamina.MaxStamina;
            }

            var isVisible = true;

            if (Application.isPlaying)
            {
                isVisible = (!HideWhenDead || Value > float.Epsilon) && (!HideWhenNone || Target != null);

                if (FillRect != null)
                {
                    FillRect.gameObject.SetActive(isVisible);
                }
                if (BackgroundRect != null)
                {
                    BackgroundRect.gameObject.SetActive(isVisible);
                }
                if (Name != null)
                {
                    Name.gameObject.SetActive(isVisible);
                }
            }

            if (isVisible)
            {
                if (Name != null)
                {
                    if (_cachedCharacterName == null)
                    {
                        if (Target != null)
                        {
                            Name.text = Target.name;
                        }
                    }
                    else
                    {
                        Name.text = _cachedCharacterName.Name;
                    }
                }

                if (FillRect != null)
                {
                    FillRect.anchorMax = new Vector2(Value, 1);
                }
            }
        }