예제 #1
0
        public Transform GetClosestTarget(Transform otherTransform)
        {
            Targetable target = null;

            var targets = gameTargets.Targets.Where(t => !t.IsInvulnerable).ToArray();


            Vector2 pos      = otherTransform.position;
            float   distance = float.PositiveInfinity;

            foreach (Targetable currentTarget in targets)
            {
                float currentDis = Vector2.Distance(currentTarget.transform.position, pos);
                if (currentDis < distance)
                {
                    distance = currentDis;
                    target   = currentTarget;
                }
            }
            if (target == null)
            {
                return(null);
            }
            return(target.transform);
        }
예제 #2
0
 public override void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.tag == "target")
     {
         Targetable target = other.gameObject.GetComponent <Targetable>();
         if (target != null && target.isAlive && !target.IsInvulnerable)
         {
             ExitTo(new EnemyAttackState(target));
         }
     }
 }
예제 #3
0
 public override void OnCollisionExit2D(Collision2D other)
 {
     if (other.gameObject.tag == "target")
     {
         Targetable _target = other.gameObject.GetComponent <Targetable>();
         if (_target != null && target == _target)
         {
             ExitTo(new EnemyPursueState());
         }
     }
 }
예제 #4
0
        private void Init()
        {
            targetable = GetComponent <Targetable>();
            targetable.RegisterOnTargetDestroyed(OnTargetDestroyed);
            targetable.RegisterOnHealthChanged(OnHealthChanged);


            foreach (var node in batteriesNodes)
            {
                node.gameObject.SetActive(false);
            }

            RegisterBattery();
            OnHealthChanged(0);
        }
예제 #5
0
 private void OnTargetInvulnerable(Targetable target)
 {
     ExitTo(new EnemyPursueState());
 }
예제 #6
0
 public EnemyAttackState(Targetable targetable)
 {
     target = targetable;
     target.RegisterOnTargetDestroyed(OnTargetDestroyed);
     target.BecameInvulnerable += OnTargetInvulnerable;
 }