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); }
public override IAState update(GameObject obj) { float dist = Vector3.Distance(targetPos, obj.transform.position); float calc = (fromAttr.arriveDist + fromCtrl.radius + (targetCtrl == null ? 0 : targetCtrl.radius)); if (dist < (fromAttr.arriveDist + (fromCtrl.radius) + (targetCtrl == null ? 0 : targetCtrl.radius))) { if (this.doWhenArrive != null) { return(this.doWhenArrive.Invoke(null)); } // We arrive to destination IdleState state = new IdleState(); state.time = fromAttr.investigateWaitTime; state.isInfinite = false; state.onComplete((s) => { return(previousState); }); return(state); } // obj.transform.LookAt(target.transform.position);/ if (navAgent) { navAgent.destination = targetPos; navAgent.speed = lineOfSight.GetStatus().Equals(LineOfSight.Status.Alerted) ? fromAttr.alertVelocity : fromAttr.velocity; if (animatorController) { animatorController.setForward(navAgent.speed); } } else { Vector3 def = targetPos - obj.transform.position; obj.transform.position += (def.normalized * fromAttr.velocity * Time.deltaTime); if (animatorController) { animatorController.setForward(fromAttr.velocity); } } return(this); }