// Use this for initialization // void Start () // { // // } // Update is called once per frame void Update() { if (CurrentGameState == EGameState.MainMenu) { #if UNITY_ANDROID if (Input.GetMouseButtonUp(0)) #else if (Input.GetKeyDown("space")) #endif { CurrentGameState = EGameState.Transition; Transition.StartFade( () => { MainMenuPanel.SetActive(false); CreditsPanel.SetActive(false); InGamePanel.SetActive(true); StartNewGame(); }, null ); } else if (Input.GetKey(KeyCode.Escape)) { CurrentGameState = EGameState.Transition; Transition.StartFade( () => { MainMenuPanel.SetActive(false); CreditsPanel.SetActive(true); InGamePanel.SetActive(false); CurrentGameState = EGameState.Credits; //Application.Quit(); }, null ); } } if (CurrentGameState == EGameState.Credits) { #if UNITY_ANDROID if (Input.GetMouseButtonUp(0)) #else if (Input.GetKeyDown("space")) #endif { CurrentGameState = EGameState.Transition; Transition.StartFade( () => { MainMenuPanel.SetActive(false); CreditsPanel.SetActive(false); InGamePanel.SetActive(true); StartNewGame(); }, null ); } else if (Input.GetKey(KeyCode.Escape)) { CurrentGameState = EGameState.Transition; Transition.StartFade( () => { Application.Quit(); }, null ); } } if (CurrentGameState == EGameState.GamePlay) { if (TimeLeft < 0f) { TimeLeft = 0f; GameOverText.gameObject.SetActive(true); gameOverPanel.gameObject.SetActive(true); #if UNITY_ANDROID GameOverText.text = "GAME OVER\nPathetic lives ruined: " + Score.ToString() + "\nTime wasted: " + ((int)TimePlayed).ToString() + "s\nTap to try again"; #else GameOverText.text = "GAME OVER\nPathetic lives ruined: " + Score.ToString() + "\nTime wasted: " + ((int)TimePlayed).ToString() + "s\nPress SPACE to try again"; #endif MoreBuildingsIndicator.gameObject.SetActive(false); HideTutorial(); // if tutorial wasn't finished, reset progress CurrentGameState = EGameState.GameOver; CameraManager.enabled = false; CurrentFloor.Reveal(false); timerContainer.SetActive(false); timerAnimation.Stop(); Sounds.PlaySound(ESoundType.GameOver); Music.PlayMusic(EMusicType.GameOver); } else { if (!IsFirstGame) { TimeLeft -= Time.deltaTime; } TimePlayed += Time.deltaTime; if (TimeLeft < animateClockWhenSecondsLeft) { timerAnimation.Play(); timerAnimation["ClockBeat"].speed = MAX_CLOCK_ANIMATION_SPEED * (1 - (TimeLeft / animateClockWhenSecondsLeft)); } if (TimeLeft < TIME_LEFT_FAST_MUSIC_TRESHOLD) { Music.PlayMusic(EMusicType.FastGameplay); } else { if (IsFirstGame) { Music.PlayMusic(EMusicType.TutorialIntro); } else { Music.PlayMusic(EMusicType.Gameplay); } } if (moreBuildingsIndicatorShown) { moreBuildingsIndicatorTimer -= Time.deltaTime; if (moreBuildingsIndicatorTimer < 0) { moreBuildingsIndicatorShown = false; MoreBuildingsIndicator.gameObject.SetActive(false); } } } // Timer.text = "Time Left: " + ((int)TimeLeft).ToString() + "s"; Timer.text = ((int)TimeLeft).ToString(); timer.fillAmount = TimeLeft / TIME_LEFT; #if UNITY_ANDROID // swipe detection source: http://pfonseca.com/swipe-detection-on-unity/ if (Input.touchCount > 0) { foreach (Touch touch in Input.touches) { switch (touch.phase) { case TouchPhase.Began: /* this is a new touch */ isSwipe = true; fingerStartTime = Time.time; fingerStartPos = touch.position; break; case TouchPhase.Canceled: /* The touch is being canceled */ isSwipe = false; break; case TouchPhase.Ended: float gestureTime = Time.time - fingerStartTime; float gestureDist = (touch.position - fingerStartPos).magnitude; bool realSwipe = false; if (isSwipe && gestureTime < maxSwipeTime && gestureDist > minSwipeDist) { Vector2 direction = touch.position - fingerStartPos; Vector2 swipeType = Vector2.zero; if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)) { // the swipe is horizontal: swipeType = Vector2.right * Mathf.Sign(direction.x); } else { // the swipe is vertical: swipeType = Vector2.up * Mathf.Sign(direction.y); } if (swipeType.x != 0.0f) { if (swipeType.x > 0.0f) { realSwipe = true; CameraManager.GoTo(Dir.W); } else { realSwipe = true; CameraManager.GoTo(Dir.E); } } if (swipeType.y != 0.0f) { if (swipeType.y > 0.0f) { realSwipe = true; CameraManager.GoTo(Dir.S); } else { realSwipe = true; CameraManager.GoTo(Dir.N); } } } if (!realSwipe && GetCurrentTapType() == EAndroidTapType.Middle) { ObjectInteraction(); } break; } } } #else if (Input.GetKeyDown("space")) { ObjectInteraction(); } #endif if (Input.GetKey(KeyCode.Escape)) { CurrentGameState = EGameState.Transition; Music.PlayMusic(EMusicType.TitleScreen); Transition.StartFade( () => { CurrentGameState = EGameState.MainMenu; MainMenuPanel.SetActive(true); CreditsPanel.SetActive(false); InGamePanel.SetActive(false); }, null ); } } else if (CurrentGameState == EGameState.GameOver) { #if UNITY_ANDROID if (Input.GetMouseButtonUp(0)) #else if (Input.GetKey("space")) #endif { CurrentGameState = EGameState.Transition; Transition.StartFade( () => { StartNewGame(); }, null ); } else if (Input.GetKey(KeyCode.Escape)) { CurrentGameState = EGameState.Transition; Music.PlayMusic(EMusicType.TitleScreen); Transition.StartFade( () => { CurrentGameState = EGameState.MainMenu; MainMenuPanel.SetActive(true); CreditsPanel.SetActive(false); InGamePanel.SetActive(false); }, null ); } } }