override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (m_unit.GetTargetUnits() == null) { return; } foreach (GameObject soldier in m_unit.GetTargetUnits()) { if (soldier.GetComponent <UnitBase>().IsDie()) { continue; } float distance = Vector2.Distance(soldier.transform.position, m_transform.position); if (distance <= m_unit.GetMonsterData().attackRange) { animator.SetBool("IsInRange", true); return; } else if (distance <= detectDistance) { m_unit.SetMainTarget(soldier); animator.SetBool("IsMove", true); return; } } }
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { int nearestSoldierIndex = -1; float unitMaxXPos = -1; for (int index = 0; index < m_soldierUnits.Count; index++) { if (m_soldierUnits[index].GetComponent <UnitBase>().IsDie()) { continue; } if (unitMaxXPos < m_soldierUnits[index].transform.position.x) { nearestSoldierIndex = index; unitMaxXPos = m_soldierUnits[index].transform.position.x; } } if (nearestSoldierIndex == -1) { animator.SetBool("IsMove", false); return; } m_transform.position = Vector2.MoveTowards(m_transform.position, m_soldierUnits[nearestSoldierIndex].transform.position, m_unit.GetMonsterData().speed); if (Vector2.Distance(m_transform.position, m_soldierUnits[nearestSoldierIndex].transform.position) <= m_unit.GetMonsterData().attackRange) { m_unit.SetMainTarget(m_soldierUnits[nearestSoldierIndex]); animator.SetBool("IsInRange", true); animator.SetBool("IsMove", false); } }