//开始搜索目标 public void SearchTargetStart(Action <Unit> onHitTargetCallback) { isSearchingTarget = true; currentTargetList = new List <Unit>(); onHitTarget = onHitTargetCallback; //对接触该碰撞体的单位施加效果 for (int i = colliderList.Count - 1; i >= 0; i--) { Unit unit = colliderList[i]; Debug.Log(unit.name); if (RelationshipManager.RelationshipBetween(holder, unit) == Relationship.Enemy) { currentTargetList.Add(unit); onHitTarget?.Invoke(unit); } } }
private void OnTriggerEnter2D(Collider2D collision) { Unit unit = collision.GetComponent <Unit>(); if (unit != null) { //Debug.Log("OnTriggerEnter2D:" + unit.name); colliderList.Add(unit); //如果在搜索目标,而且目标是敌人,触发效果 if (isSearchingTarget && RelationshipManager.RelationshipBetween(holder, unit) == Relationship.Enemy) { //没在已成为目标的List中 if (!currentTargetList.Contains(unit)) { currentTargetList.Add(unit); onHitTarget?.Invoke(collision.GetComponent <Unit>()); } } } }