void Jump() { Direction direction = _solution.Dequeue(); int nextRow = -1; int nextColumn = -1; if (NextCell(direction, ref nextRow, ref nextColumn)) { // Set direction SetDirection(direction); // Get foothold type FootholdType type = _types[_curRow, _curColumn]; // Update foothold if (type == FootholdType.Double) { // Set foothold SetFoothold(_curRow, _curColumn, FootholdType.Normal); } else if (type != FootholdType.None) { // Set foothold SetFoothold(_curRow, _curColumn, FootholdType.None); } // Set next cell _curRow = nextRow; _curColumn = nextColumn; // Jump var jump = MoveAction.MoveTo(GetPosition(nextRow, nextColumn), jumpDuration * 0.5f); var delay = DelayAction.Create(jumpDuration * 0.5f); var callFunc = CallFuncAction.Create(JumpCallback); var action = SequenceAction.Create(jump, delay, callFunc); _frog.gameObject.Play(action); } }
IEnumerator Try() { int nextRow = -1; int nextColumn = -1; for (int i = 0; i < 4; i++) { Direction dir = Directions[i]; if (!dir.IsOpposite(_curDirection)) { if (NextCell(dir, ref nextRow, ref nextColumn)) { // Push _cells.Push(new Cell(_curRow, _curColumn)); // Save cell int row = _curRow; int column = _curColumn; // Save direction Direction direction = _curDirection; FootholdType type1 = _types[_curRow, _curColumn]; FootholdType type2 = _types[nextRow, nextColumn]; // Set direction SetDirection(dir); // Update current cell if (type1 == FootholdType.Double) { // Set foothold SetFoothold(_curRow, _curColumn, FootholdType.Normal); // Increase counter _count++; } else if (type1 != FootholdType.None) { // Set foothold SetFoothold(_curRow, _curColumn, FootholdType.None); // Increase counter _count++; } // Jump var jump = MoveAction.MoveTo(GetPosition(nextRow, nextColumn), jumpDuration * 0.5f); if (type2.IsRedirect()) { Direction newDirection = type2.GetDirection(); _frog.gameObject.Play(SequenceAction.Create(jump, CallFuncAction.Create(() => { SetDirection(newDirection); }))); } else { _frog.gameObject.Play(jump); } // Set current cell to next one _curRow = nextRow; _curColumn = nextColumn; yield return(new WaitForSeconds(jumpDuration)); // Check if finished if (_count == _total - 1) { Show(); } else { yield return(StartCoroutine(Try())); } // Restore cell _curRow = row; _curColumn = column; // Restore position _frog.transform.position = GetPosition(_curRow, _curColumn); // Restore type if (type1 != FootholdType.None) { // Set foothold SetFoothold(_curRow, _curColumn, type1); // Decrease counter _count--; } // Restore direction SetDirection(direction); // Pop _cells.Pop(); yield return(new WaitForSeconds(unjumpDuration)); } } } }