void WaitTimerForExtraBehaviours(WaypointsBase wp, List <WaypointsBase> listOfWp) { if (listOfWp.Count > 1) { #region WaitTime _waitTime += Time.deltaTime; if (_waitTime > wp.waitTime) { if (circularList) { if (waypoints.Count - 1 > indexBehaviour) { indexBehaviour++; } else { indexBehaviour = 0; } } else { if (!descendingList) { if (waypoints.Count - 1 == indexBehaviour) { descendingList = true; indexBehaviour--; } else { indexBehaviour++; } } else { if (indexBehaviour > 0) { indexBehaviour--; } else { descendingList = false; indexBehaviour++; } } } _initCheck = false; goToPos = false; _waitTime = 0; } #endregion } }
void WaitTimerForEachWP(WaypointsBase wp, List <WaypointsBase> listOfWp) { if (listOfWp.Count > 1) { #region WaitTime _waitTime += Time.deltaTime; if (_waitTime > wp.waitTime) { if (circularList) { if (listOfWp.Count - 1 > indexWayPoint) { indexWayPoint++; } else { indexWayPoint = 0; } } else { if (!descendingLIst) { if (listOfWp.Count - 1 == indexWayPoint) { descendingLIst = true; indexWayPoint--; } else { indexWayPoint++; } } } _initCheck = false; goToPos = false; _waitTime = 0; } #endregion } }
void OnAlertExtraBehaviours() { if (onAlertExtraBehaviours.Count > 0) { WaypointsBase curBehaviour = onAlertExtraBehaviours[indexBehaviour]; if (!goToPos) { charStatEnm.MoveToPosition(curBehaviour.targetDestination.position); goToPos = true; } else { float dstToTarget = Vector3.Distance(transform.position, curBehaviour.targetDestination.position); if (dstToTarget < enmControl.stopDistance) { CheckWaypoint(curBehaviour, 1); } } } }
void PatrolBehavior() { if (waypoints.Count > 0) { WaypointsBase curWaypoint = waypoints[indexWayPoint]; if (!goToPos) { charState.MoveToPosition(curWaypoint.targetDestination.position); goToPos = true; } else { float distanceToTarget = Vector3.Distance(transform.position, curWaypoint.targetDestination.position); if (distanceToTarget < 10) { CheckWayPoint(curWaypoint, 0); } } } }
public void OnAlertExtraBehavior() { if (onAlertExtraBehaviors.Count > 0) { WaypointsBase curBehavior = onAlertExtraBehaviors[indexBehavior]; if (!goToPos) { charState.MoveToPosition(curBehavior.targetDestination.position); goToPos = true; } else { float distanceToTarget = Vector3.Distance(transform.position, curBehavior.targetDestination.position); if (distanceToTarget < atackRange) { CheckWayPoint(curBehavior, 1); } } } }
void PatrolBehaviour() { if (waypoints.Count > 0) { WaypointsBase curWaypoint = waypoints[indexWaypoints]; if (!goToPos) { charStatEnm.MoveToPosition(curWaypoint.targetDestination.position); goToPos = true; } else { float dstToTarget = Vector3.Distance(transform.position, curWaypoint.targetDestination.position); if (dstToTarget < enmControl.stopDistance) { CheckWaypoint(curWaypoint, 0); } } } }
void CheckWayPoint(WaypointsBase wp, int listCase) { #region InitCheck if (!_initCheck) { _lookAtTarget = wp.lookTowards; _overrideAnimation = wp.overrideAnimation; _initCheck = true; } #endregion if (!wp.stopList) { switch (listCase) { case 0: WaitTimerForEachWP(wp, waypoints); break; case 1: WaitTimerForExtraBehaviors(wp, onAlertExtraBehaviors); break; } } #region LookTowards if (_lookAtTarget) { float speedToRotate; if (wp.speedToLook < 0.1f) { speedToRotate = 2; } else { speedToRotate = wp.speedToLook; } Vector3 direction = wp.TargetToLookTo.position - transform.position; direction.y = 0; float angle = Vector3.Angle(transform.forward, direction); if (angle > 0.1f) { targetRoot = Quaternion.LookRotation(direction); transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRoot, Time.deltaTime * wp.speedToLook); } else { _lookAtTarget = false; } } #endregion #region AnimationOverride if (_overrideAnimation) { if (wp.animationRoutines.Length > 0) { for (int i = 0; i < wp.animationRoutines.Length; i++) { charState.CallFunctionWithString(wp.animationRoutines[i], 0); } } else { Debug.Log("error"); } _overrideAnimation = false; } #endregion }