IEnumerator MoveToPoint(Transform currentPoint, PuzzlePathComponent destination, List <PuzzlePathComponent> completePath) { AC.KickStarter.player.Halt(); isFuckingMoving = true; for (int i = completePath.Count - 1; i > 0; i--) { if (OnLightpointMove != null) { OnLightpointMove(completePath[i]); } yield return(MoveToPoint(currentPoint, completePath[i])); currentLocation = completePath[i]; //Debug.Log("moved to " + completePath[i].transform.position); } // Completed the puzzle if (destination.xpos == 1 && destination.ypos == 7) { // Win scenario //moveAwayInteraction.Interact(); if (winInteraction != null) { winInteraction.Interact(); } } // if(OnLightpointMove != null) // OnLightpointMove(destination); isFuckingMoving = false; }
bool ScanForPath(PuzzlePathComponent currentLocation, PuzzlePathComponent pathPoint, List <PuzzlePathComponent> completePath, List <PuzzlePathComponent> totalScanned) { if (totalScanned.Contains(currentLocation)) { return(false); } totalScanned.Add(currentLocation); if (currentLocation == pathPoint) { completePath.Add(currentLocation); return(true); } foreach (var path in currentLocation.connectedTo) { if (ScanForPath(path, pathPoint, completePath, totalScanned)) { completePath.Add(path); return(true); } } return(false); }
IEnumerator MoveToPoint(Transform currentPoint, PuzzlePathComponent endPoint) { moveSoundSource.Play(); Transform dest = endPoint.transform; Vector3 step = (dest.position - currentPoint.position) / framesPerStep; while (Vector3.Magnitude(currentPoint.position - dest.position) > marginOfError) { currentPoint.position = currentPoint.position + step; yield return(new WaitForSeconds(0.02f)); } currentPoint.position = dest.position; }
void TryMoveToPos(PuzzlePathComponent pathPoint) { if (StaffHeadColor.CurrentColorIndex != staffColorIndex || isFuckingMoving) { return; } List <PuzzlePathComponent> completePath = new List <PuzzlePathComponent>(); List <PuzzlePathComponent> totalScanned = new List <PuzzlePathComponent>(); if (ScanForPath(currentLocation, pathPoint, completePath, totalScanned)) { MoveLightPointToEnd(pathPoint, completePath); } }
// Called by an event. When one moves, all of them move. private void MoveLightPoint(PuzzlePathComponent destination) { if (isFuckingMoving) { return; } var path = paths.FirstOrDefault(t => t.xpos == destination.xpos && t.ypos == destination.ypos); if (path != null) { StartCoroutine(MoveToPoint(LightPoint.transform, path)); currentLocation = path; } }
private void MoveLightPointToEnd(PuzzlePathComponent destination, List <PuzzlePathComponent> completePath) { StartCoroutine(MoveToPoint(LightPoint.transform, destination, completePath)); }