Beispiel #1
0
 private void Awake()
 {
     _actor  = GetComponent <Actor>();
     _health = GetComponent <CharacterHealth>();
 }
Beispiel #2
0
        private void LateUpdate()
        {
            if (Target != _cachedTarget)
            {
                _cachedTarget = Target;

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

            if (_cachedCharacterHealth != null)
            {
                Value = _cachedCharacterHealth.Health / _cachedCharacterHealth.MaxHealth;
            }

            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);
                }
            }
        }
Beispiel #3
0
 // Start is called before the first frame update
 void Start()
 {
     characterEffects = cowboy.GetComponent <CharacterEffects>();
     characterHealth  = cowboy.GetComponent <CharacterHealth>();
 }
Beispiel #4
0
 private void Awake()
 {
     _health = GetComponent <CharacterHealth>();
 }
Beispiel #5
0
        /// <summary>
        /// Finds an object and a hit position a bullet would hit if fired. Checks if it is a friend.
        /// </summary>
        public RaycastHit Raycast(Vector3 origin, Vector3 direction, out bool isFriend, bool friendCheck)
        {
            RaycastHit closestHit      = new RaycastHit();
            float      closestDistance = Distance * 10;

            var minDistance = 0f;

            if (_isUsingCustomRaycast)
            {
                minDistance = Vector3.Distance(Origin, RaycastOrigin);
            }

            if (minDistance > 0.5f)
            {
                minDistance -= 0.5f;
            }

            isFriend = false;
            var count = Physics.RaycastNonAlloc(origin, direction, _hits, Distance);

            for (int i = 0; i < count; i++)
            {
                var hit = _hits[i];

                if (Character != null && Util.InHiearchyOf(hit.collider.gameObject, Character.gameObject))
                {
                    continue;
                }

                if (hit.distance < closestDistance && hit.distance > minDistance)
                {
                    var isOk     = true;
                    var isShield = false;

                    if (hit.collider.isTrigger)
                    {
                        if (BodyPartHealth.Contains(hit.collider.gameObject))
                        {
                            isOk = true;
                        }
                        else
                        {
                            var shield = BulletShield.Get(hit.collider.gameObject);

                            if (shield != null)
                            {
                                if (Vector3.Dot(shield.transform.forward, hit.normal) >= -0.2f)
                                {
                                    isOk     = true;
                                    isShield = true;
                                }
                                else
                                {
                                    isOk = false;
                                }
                            }
                            else
                            {
                                isOk = false;
                            }
                        }
                    }
                    else
                    {
                        var health = CharacterHealth.Get(hit.collider.gameObject);

                        if (health != null)
                        {
                            isOk = health.IsRegisteringHits;
                        }
                    }

                    if (isOk)
                    {
                        if (!isShield && (_isIgnoringSelf || _hasFireCondition) && friendCheck)
                        {
                            var root = getHealthTarget(hit.collider.gameObject);

                            if (root != null)
                            {
                                if (_isIgnoringSelf && Character != null && root == Character.gameObject)
                                {
                                    isFriend = true;
                                }
                                else if (_hasFireCondition)
                                {
                                    var actor = Actors.Get(root);

                                    if (actor != null)
                                    {
                                        isFriend = actor.Side == _fireConditionSide;
                                    }
                                    else
                                    {
                                        isFriend = false;
                                    }
                                }
                                else
                                {
                                    isFriend = false;
                                }
                            }
                            else
                            {
                                isFriend = false;
                            }
                        }

                        closestHit      = hit;
                        closestDistance = hit.distance;
                    }
                }
            }

            return(closestHit);
        }