public override IAState update(GameObject obj) { // just validation if (obj == null || !fromAttr.isAlive().GetValueOrDefault(false)) { return(null); } foreach (string tag in this.searchTags) { if (_lineOfSight.SeeByTag(tag)) { List <GameObject> inFView = _lineOfSight.getViewing(); foreach (GameObject c in inFView) { IAState n = notify(c.gameObject, _lineOfSight.GetStatus().Equals(LineOfSight.Status.Alerted)); if (n != null) { manager.setCurrentState(n); } } } } return(this); }
void FixedUpdate() { lineOfSight.enabled = _config.lightIsOn; lineOfSight.SetStatus(LineOfSight.Status.Idle); if (lineOfSight.enabled) { if (lineOfSight.SeeByTag("Player")) { List <GameObject> obs = lineOfSight.getViewing(); GameObject obj = obs[0]; Player player = obj.GetComponent <Player>(); if (player != null) { if (!player.disguised) { Collider[] colliders = Physics.OverlapSphere(gameObject.transform.position, alertRadious); GameObject nearest = null; float nearestDist = 0f; foreach (Collider c in colliders) { if (c.tag.Equals("Soldier")) { float dist = Vector3.Distance(c.gameObject.transform.position, transform.position); if (nearest == null || dist < nearestDist) { nearestDist = dist; nearest = c.gameObject; } } } if (nearest != null) { FSMManager g = nearest.GetComponent <FSMManager>(); BasicObjectAttr attr = nearest.GetComponent <BasicObjectAttr>(); // We arrive to destination List <SearchConfig> searchConf = g.GetBasicState().GetSearchConfig(); foreach (SearchConfig sc in searchConf) { if (sc.doWhenAlert != null) { IAState st = sc.doWhenAlert.Invoke(obj); g.setCurrentState(st); } } } lineOfSight.SetStatus(LineOfSight.Status.Alerted); } else { lineOfSight.SetStatus(LineOfSight.Status.Suspicious); } } } } }
void Update() { if (_lineOfSight.SeeByTag("Player")) { foreach (GameObject ob in _lineOfSight.getViewing()) { float dist = Vector3.Distance(ob.transform.position, transform.position); Player p = ob.GetComponent <Player>(); float percent = dist / _lineOfSight.GetMaxDist(); bool alerted = percent < alertDistPercent; if (alerted || _config.alert) { _lineOfSight.SetStatus(LineOfSight.Status.Alerted); } else { if (p && p.disguised) { _lineOfSight.SetStatus(LineOfSight.Status.Suspicious); } else { _lineOfSight.SetStatus(LineOfSight.Status.Alerted); } } } } else { _lineOfSight.SetStatus(LineOfSight.Status.Idle); } }
private void Update() { // STEP 3: Automatically check if viewer sees anything marked by given tag if (_lineOfSight.SeeByTag("Player")) { // STEP 4: Change the color of viewing area _lineOfSight.SetStatus(LineOfSight.Status.Alerted); } else { // STEP 5: Change the color of viewing area back to normal _lineOfSight.SetStatus(LineOfSight.Status.Idle); } }