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 } } }
public void Attack(Transform NewTarget) { MinimumDistanceToTarget = 0f; BeforeAttackBehaviour = MyBehaviour; MyBehaviour = MinionBehaviour.Attack; AttackTransform = NewTarget; }
public void OnHit(Character2D MyCharacter) { if (MyCharacter && MyBehaviour != MinionBehaviour.Attack) { MinimumDistanceToTarget = 0f; BeforeAttackBehaviour = MyBehaviour; MyBehaviour = MinionBehaviour.Attack; AttackTransform = MyCharacter.transform; } }
public void StopAttacking() { MinimumDistanceToTarget = 0.3f; if (BeforeAttackBehaviour == MinionBehaviour.Attack) { Debug.LogError("BAD: " + BeforeAttackBehaviour.ToString()); MyBehaviour = MinionBehaviour.Wander; } else { MyBehaviour = BeforeAttackBehaviour; } }
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; }
public void WanderAndDestroy() { MinimumDistanceToTarget = 0f; MyBehaviour = MinionBehaviour.SeekTarget; }
public void Wander() { MinimumDistanceToTarget = 0f; MyBehaviour = MinionBehaviour.Wander; }
public void Follow() { MinimumDistanceToTarget = 0.6f; MyBehaviour = MinionBehaviour.Follow; }