protected override IEnumerator MoveToTargetRoutine() { if (state != EnemyState.Alarm) { yield return(new WaitForSeconds(2f)); FinishMovementEvent.Invoke(); yield break; } var startPos = new Vector3(currentNode.Coordinate.x, 0f, currentNode.Coordinate.y); var newDest = pathToTarget[currentPathIndex].transform.position; Move(newDest, 0f); while (isMoving) { yield return(null); } currentPathIndex++; if (currentPathIndex >= pathToTarget.Count) { FindPathToPlayer(); } FinishMovementEvent.Invoke(); }
IEnumerator PatrolRoutine() { if (board != null) { Node currentNode = board.FindNodeAt(transform.position); Vector3 startPosition = new Vector3(currentNode.Coordinate.x, 0, currentNode.Coordinate.y); Vector3 destination = startPosition + transform.TransformVector(moveDirection); Vector3 nextDestination = startPosition + transform.TransformVector(moveDirection * 2); Node destinationNode = board.FindNodeAt(destination); Node nextDestinationNode = board.FindNodeAt(nextDestination); Move(destination); while (IsMoving) { yield return(null); } if (nextDestinationNode == null || !destinationNode.LinkedNodes.Contains(nextDestinationNode)) { destination = startPosition; FaceDestination(startPosition); yield return(new WaitForSeconds(turnSpeed)); } } FinishMovementEvent.Invoke(); }
IEnumerator StandRoutine() { yield return(null); FinishMovementEvent.Invoke(); }
//TODO Pass in rotation direction IEnumerator SpinRoutine(RotationDirection direction) { int counter = 0; switch (rotationDirection) { case RotationDirection.Clockwise: counter = 1; break; case RotationDirection.Anticlockwise: counter = 3; break; default: break; } Vector3 nextDirection; Vector3 destination = Vector3.forward * Board.spacing; float xPos; float zPos; Node currentNode = board.FindNodeAt(transform.position); Node destinationNode = null; while (destinationNode == null) { if (counter > 4 || counter < 0) { break; } xPos = Board.spacing * Mathf.Sin((Mathf.PI / 2) * counter); zPos = Board.spacing * Mathf.Cos((Mathf.PI / 2) * counter); nextDirection = new Vector3(xPos, 0, zPos); destination = transform.position + transform.TransformVector(nextDirection); destinationNode = board.FindNodeAt(destination); if (!currentNode.LinkedNodes.Contains(destinationNode)) { destinationNode = null; } switch (rotationDirection) { case RotationDirection.Clockwise: counter++; break; case RotationDirection.Anticlockwise: counter--; break; default: break; } } if (destinationNode != null) { FaceDestination(destination); yield return(new WaitForSeconds(turnSpeed)); } FinishMovementEvent.Invoke(); }