Exemplo n.º 1
0
        public override bool AttackNearestTarget()
        {
            var alreadGotAValidTarget = CurrentTarget != null && CurrentTarget.Targetable;

            if (alreadGotAValidTarget || !(nextAttackPossible < Time.time))
            {
                return(InRange);
            }
            var findNewTarget = nearestTarget == null ||
                                !IsInRange(nearestTarget) ||
                                !IsInLineOfSight(nearestTarget.gameObject) ||
                                !nearestTarget.Targetable;

            if (findNewTarget)
            {
                var target = TargetManager.Instance.GetEnemies(team)
                             .Where(o => {
                    var dmg = o.GetComponent <Damageable>();
                    return(dmg != null && dmg.Targetable);
                })
                             .Where(IsInLineOfSight)
                             .Aggregate(null, PositionUtil.FindNearest(gameObject.transform.position));
                nearestTarget = target != null?target.GetComponent <Damageable>() : null;
            }
            CurrentTarget = nearestTarget;
            return(InRange);
        }
Exemplo n.º 2
0
        private void Update()
        {
            if (NotActive())
            {
                return;
            }
            if (animator != null)
            {
                animator.SetFloat("Speed", agent.velocity.magnitude);
            }
            if (nextEnemyCheck <= Time.time)
            {
                attack.SetTarget(
                    TargetManager.Instance.GetValidEnemyTargets(team)
                    .Select(dmg => dmg.gameObject)
                    .Aggregate(null, PositionUtil.FindNearest(gameObject.transform.position))
                    .GetComponent <Damageable>());

                nextEnemyCheck = Time.time + ReevaluateInterval;
            }
            agent.isStopped = attack.InRange;
            var t = attack.GetTarget();

            if (t != null)
            {
                agent.SetDestination(t.gameObject.transform.position);
            }
        }