IEnumerator GetToCover() { Vector3 directionToCover = Vector3.zero; float coverDistance = Mathf.Infinity; if (cover != null) { cover.SetOccupant(null); } cover = null; Collider[] nearbyCover = Physics.OverlapSphere(transform.position, senseRadius, visibleToAI); Cover_FSM theCover; float closest = Mathf.Infinity; for (int i = 0; i < nearbyCover.Length; i++) { theCover = nearbyCover[i].GetComponent <Cover_FSM>(); if (theCover != null && theCover.occupied == false) { coverDistance = Vector3.Distance(anomalyLocation, theCover.transform.position); directionToCover = ((theCover.transform.position + theCover.transform.up) - anomalyLocation).normalized; if (Physics.Raycast(anomalyLocation, directionToCover, coverDistance, gameController.obscuresVision)) { if (coverClosestToEnemy == false) { coverDistance = Vector3.Distance(transform.position, theCover.transform.position); } if (closest > coverDistance) { closest = coverDistance; cover = theCover; } } } } if (cover != null) { cover.SetOccupant(entity); pathfinder.speed = entity.runSpeed; pathfinder.destination = cover.transform.position; } while (cover != null && transform.position != pathfinder.destination) { yield return(null); } if (gameController.alertAlreadyActive) { StartCoroutine(EngageHostile()); } else { StartCoroutine(RadioHQ("I see an intruder! Requesting backup!", true, AIStates.Alert)); } }
public void Die() { StopAllCoroutines(); expressionText.text = ""; if (cover != null) { cover.SetOccupant(null); cover = null; } pathfinder.destination = transform.position; this.enabled = false; }
public void AIStateEnded() { currentState = gameController.currentState.stateName; if (currentState == AIStates.Caution || currentState == AIStates.Intrusion) { busy = false; if (cover != null) { cover.SetOccupant(null); cover = null; } } }