Exemple #1
0
 public void AttackClosest()
 {
     if (MyBehaviour != MinionBehaviour.Attack)
     {
         MinionControl2D[] MyObjects       = GameObject.FindObjectsOfType <MinionControl2D>();
         float             ClosestDistance = MaxAttackDistance;
         MinionControl2D   ClosestObject   = null;
         for (int i = 0; i < MyObjects.Length; i++)
         {
             if (MyObjects[i] != this)
             {
                 float ThisDistance = Vector3.Distance(transform.position, MyObjects[i].transform.position);
                 if (ThisDistance < ClosestDistance)
                 {
                     ClosestDistance = ThisDistance;
                     ClosestObject   = MyObjects[i];
                 }
             }
         }
         if (ClosestObject != null)
         {
             MinimumDistanceToTarget = 0f;
             BeforeAttackBehaviour   = MyBehaviour;
             MyBehaviour             = MinionBehaviour.Attack;
             AttackTransform         = ClosestObject.transform;
         }
         else
         {
             // keep following?! or wandering
         }
     }
 }
Exemple #2
0
 public void Attack(Transform NewTarget)
 {
     MinimumDistanceToTarget = 0f;
     BeforeAttackBehaviour   = MyBehaviour;
     MyBehaviour             = MinionBehaviour.Attack;
     AttackTransform         = NewTarget;
 }
Exemple #3
0
 public void OnHit(Character2D MyCharacter)
 {
     if (MyCharacter && MyBehaviour != MinionBehaviour.Attack)
     {
         MinimumDistanceToTarget = 0f;
         BeforeAttackBehaviour   = MyBehaviour;
         MyBehaviour             = MinionBehaviour.Attack;
         AttackTransform         = MyCharacter.transform;
     }
 }
Exemple #4
0
 public void StopAttacking()
 {
     MinimumDistanceToTarget = 0.3f;
     if (BeforeAttackBehaviour == MinionBehaviour.Attack)
     {
         Debug.LogError("BAD: " + BeforeAttackBehaviour.ToString());
         MyBehaviour = MinionBehaviour.Wander;
     }
     else
     {
         MyBehaviour = BeforeAttackBehaviour;
     }
 }
Exemple #5
0
        public System.Collections.IEnumerator WalkToTarget(Transform NewTarget, float NewMinimumDistance)
        {
            bool  CouldMove          = MyCharacter.CanMove;
            float OldMinimumDistance = MinimumDistanceToTarget;

            MinimumDistanceToTarget = NewMinimumDistance;
            MyCharacter.SetMovement(true);
            FollowTransform  = NewTarget;
            MyBehaviour      = MinionBehaviour.Follow;
            HasReachedTarget = false;
            while (!HasReachedTarget)
            {
                yield return(new WaitForEndOfFrame());
            }
            MyCharacter.SetMovement(CouldMove);
            MinimumDistanceToTarget = OldMinimumDistance;
        }
Exemple #6
0
 public void WanderAndDestroy()
 {
     MinimumDistanceToTarget = 0f;
     MyBehaviour             = MinionBehaviour.SeekTarget;
 }
Exemple #7
0
 public void Wander()
 {
     MinimumDistanceToTarget = 0f;
     MyBehaviour             = MinionBehaviour.Wander;
 }
Exemple #8
0
 public void Follow()
 {
     MinimumDistanceToTarget = 0.6f;
     MyBehaviour             = MinionBehaviour.Follow;
 }