void TransitionToNextLevel() { if (levelIndex == levelTexts.Length - 1) { victoryText = string.Format("Thanks for playing!\nYou won in {0} {1}.\nYou caused {2} {3}.\nHold Esc to quit.", clickTally, clickTally == 1 ? "click" : "clicks", crashTally, crashTally == 1 ? "crash" : "crashes"); return; } levelIndex++; lastLevel = level; lastRoot = root; Restart(false); // Place the newly constructed level. List <LevelExitDirection> possibleDirections = new List <LevelExitDirection>(Enum.GetValues(typeof(LevelExitDirection)) as LevelExitDirection[]); possibleDirections.Remove(lastLevel.exitDirection); possibleDirections.Remove(Util.GetOppositeDirection(level.exitDirection)); LevelExitDirection direction = possibleDirections[UnityEngine.Random.Range(0, possibleDirections.Count)]; transitionT = 0; transitionTo = root.transform.localPosition; root.transform.localPosition += Util.GetDirectionVector(direction, TRANSITION_DISTANCE); transitionFrom = root.transform.localPosition; }
public static Vector3 GetDirectionVector(LevelExitDirection direction, float magnitude) { if (direction == LevelExitDirection.Down) { return(new Vector3(0, 0, -magnitude)); } if (direction == LevelExitDirection.Left) { return(new Vector3(-magnitude, 0, 0)); } if (direction == LevelExitDirection.Right) { return(new Vector3(magnitude, 0, 0)); } return(new Vector3(0, 0, magnitude)); }
public static LevelExitDirection GetOppositeDirection(LevelExitDirection direction) { if (direction == LevelExitDirection.Down) { return(LevelExitDirection.Up); } if (direction == LevelExitDirection.Left) { return(LevelExitDirection.Right); } if (direction == LevelExitDirection.Right) { return(LevelExitDirection.Left); } return(LevelExitDirection.Down); }