private void Update() { if (lastSwitchState != Switch) { lastSwitchState = Switch; if (Switch) { if (RadarType == RadarTypes.ActiveRadar) { ActivateDetectionZone(); } else { OnNotifyActiveRadarForNewTarget?.Invoke(parentBlock.GetComponent <RocketScript>().GroupFireKey.GetKey(0)); } } else { DeactivateDetectionZone(); } } if (!Switch) { return; } if (StatMaster.isClient) { return; } if (canBeOverridden || RadarType == RadarTypes.PassiveRadar) { return; } if (RadarTarget != null) { if (!InRadarRange(RadarTarget)) { ClearTarget(true); } } if (targetList.Count > 0 && !targetList.SetEquals(lastTargetList) || RadarTarget == null) { #if DEBUG //Debug.Log(blockList.Count)); #endif if (!isChoosingBlock) { #if DEBUG Debug.Log("choose target"); #endif isChoosingBlock = true; lastTargetList = targetList; if (RadarTarget == null) { RadarTarget = new Target(); } ChooseTargetInTargetList(targetList); void ChooseTargetInTargetList(HashSet <Target> targets) { foreach (var itemTarget in targets) { CompareTarget(itemTarget); } isChoosingBlock = false; void CompareTarget(Target other) { //Debug.Log(ignoreList.Contains(other.ReturnTargetName()) + " exist"); //if (ignoreList.Contains(other.ReturnTargetName())) return; if (CheckIfSameGroupRocket(other)) { return; } RadarTarget.RefreshWarningValue(); other.RefreshWarningValue(); if (other.WarningValue > RadarTarget.WarningValue) { SetTarget(other); } else if (other.WarningValue == RadarTarget.WarningValue) { var distance = (other.Position - transform.position).magnitude; if (distance < TargetDistance) { SetTarget(other); } } } bool CheckIfSameGroupRocket(Target target) { if (StatMaster.isMP) { return(false); } if (target.ReturnTimedrocket() == null) { return(false); } RocketScript rs = target.ReturnBlockBehaviour().GetComponentInAll <RocketScript>(); RocketScript selfRS = parentBlock.GetComponentInAll <RocketScript>(); if (selfRS == null) { return(false); } if (rs == null) { return(false); } if (selfRS.SPTeamKey.GetKey(0) == rs.SPTeamKey.GetKey(0)) { return(true); } return(false); } } } } }