public void setNoiseHeard(Vector3 pos, float range) { if (seenHostile == true || swatHere == false) { return; } foreach (GameObject g in swatInLevel) { float d = Vector3.Distance(pos, g.transform.position); if (d < range) { pointToInvestigate = pos; if (swatGoingToCurrentPoint == null) { swatInvestigating = swatInLevel [0]; } else { swatInvestigating = swatGoingToCurrentPoint; } NPCController npc = swatInvestigating.GetComponent <NPCController> (); if (npc.currentBehaviour == null) { } else { Destroy(npc.currentBehaviour); } investigate = swatInvestigating.AddComponent <NPCBehaviour_SwatInvestigatePoint> (); npc.currentBehaviour = investigate; investigatePoint = true; break; } } }
/// <summary> /// Checks for if any swat are dead and will remove them from active swat + fix any behaviours if they were the swat member currently going to the point. /// </summary> void shouldWeRefreshSWAT() { bool refresh = false; if (swatInLevel == null) { return; } foreach (GameObject g in swatInLevel) { NPCController npc = g.GetComponent <NPCController> (); if (npc == null) { continue; } if (npc.npcB.myType == AIType.swat) { //Debug.Log (npc.gameObject.name+ " Fount swat with " + npc.myHealth.healthValue); if (npc.gameObject.tag == "Dead/Knocked" && npc.myHealth.healthValue <= 0) { refresh = true; } } } if (refresh == true) { //Debug.Log ("Refreshing swat"); List <NPCController> swatAvailable = new List <NPCController> (); foreach (GameObject g in swatInLevel) { NPCController npc = g.GetComponent <NPCController> (); if (npc.npcB.myType == AIType.swat) { if (npc.myHealth.healthValue > 0) { swatAvailable.Add(npc); } } } if (buildingSurrounded == true) { if (investigatePoint == true) { NPCController investigatingController = swatInvestigating.GetComponent <NPCController> (); if (swatAvailable.Contains(investigatingController) == false) { swatInvestigating = swatAvailable [0].gameObject; NPCController npc = swatInvestigating.GetComponent <NPCController> (); if (npc.currentBehaviour == null) { } else { Destroy(npc.currentBehaviour); } investigate = swatInvestigating.AddComponent <NPCBehaviour_SwatInvestigatePoint> (); npc.currentBehaviour = investigate; investigatePoint = true; } } else if (investigatePoint == false && seenHostile == false) { if (goingToRoom == true) { goToEntrance = new List <NPCBehaviour_SwatGoToRoomEntrance> (); foreach (NPCController n in swatAvailable) { if (n.currentBehaviour == null) { } else { Destroy(n.currentBehaviour); } NPCBehaviour_SwatGoToRoomEntrance nb = n.gameObject.AddComponent <NPCBehaviour_SwatGoToRoomEntrance> (); n.currentBehaviour = nb; goToEntrance.Add(nb); } } else { NPCController investigatingController = swatGoingToCurrentPoint.GetComponent <NPCController> (); if (swatAvailable.Contains(investigatingController) == false) { swatGoingToCurrentPoint = swatAvailable [0].gameObject; NPCController npc = swatGoingToCurrentPoint.GetComponent <NPCController> (); if (npc.currentBehaviour == null) { } else { Destroy(npc.currentBehaviour); } nb = swatGoingToCurrentPoint.AddComponent <NPCBehaviour_SwatGoToPoint> (); npc.currentBehaviour = nb; } } } } swatInLevel.Clear(); foreach (NPCController n in swatAvailable) { swatInLevel.Add(n.gameObject); } } }