/// <summary> /// This function monitor player touches on UI buttons. /// detects both touch and clicks and can be used with editor, handheld device and /// every other platforms at once. /// </summary> void touchManager() { if (Input.GetMouseButtonUp(0)) { RaycastHit hitInfo; Ray ray = uiCam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hitInfo)) { GameObject objectHit = hitInfo.transform.gameObject; //if we are selecting a new skin if (objectHit.tag == "BtnSkin") { StartCoroutine(animateButton(hitInfo.transform.gameObject)); playSfx(tapSfx); //get btn skin ID int btnID = objectHit.GetComponent <SkinButtonController>().skinButtonID; //save selected skin PlayerPrefs.SetInt("SkinID", btnID); //apply selected skin print("btnID: " + btnID); GC.GetComponent <GameController>().manageSpaceshipSkin(btnID); } //if we are interacting with other UI elements switch (objectHit.name) { /* * we do not need pause system in this fast paced game... * * case "Button-Pause": * switch (currentStatus) { * case Status.PLAY: * PauseGame(); * break; * case Status.PAUSE: * UnPauseGame(); * break; * default: * currentStatus = Status.PLAY; * break; * } * break; * * case "Btn-Resume": * switch (currentStatus) { * case Status.PLAY: * PauseGame(); * break; * case Status.PAUSE: * UnPauseGame(); * break; * default: * currentStatus = Status.PLAY; * break; * } * break; */ case "Btn-Restart": case "uiButton-Play": UnPauseGame(); SceneManager.LoadScene(SceneManager.GetActiveScene().name); break; case "uiButton-Upgrade": StartCoroutine(animateButton(hitInfo.transform.gameObject)); //check if player has enough coins to upgrade if (GameController.playerCoin >= GameController.upgradePrice && GameController.canUpgrade) { print("We have enough coins to upgrade the rocket"); //playSfx playSfx(canBuy); canTap = false; //save available coins PlayerPrefs.SetInt("PlayerCoin", GameController.playerCoin - GameController.upgradePrice); //upgrade the rocket int rocketLevel = PlayerPrefs.GetInt("RocketLevel"); PlayerPrefs.SetInt("RocketLevel", ++rocketLevel); //reload level with new rocket SceneManager.LoadScene(SceneManager.GetActiveScene().name); } else { print("Insufficient coins"); playSfx(cantBuy); } break; case "uiButton-SwitchStartingPlanet": StartCoroutine(animateButton(hitInfo.transform.gameObject)); playSfx(tapSfx); if (GameController.startingPlanetID == 0) { PlayerPrefs.SetInt("StartingPlanetID", 1); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } else if (GameController.startingPlanetID == 1) { PlayerPrefs.SetInt("StartingPlanetID", 0); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } break; case "uiButton-NewSkin": StartCoroutine(animateButton(hitInfo.transform.gameObject)); playSfx(tapSfx); isSkinCellVisible = !isSkinCellVisible; uiNewSkinCell.SetActive(isSkinCellVisible); break; case "uiButton-HireAstronaut": StartCoroutine(animateButton(hitInfo.transform.gameObject)); //check if player has enough money to hire new astronaut, or if there is space for new hiring if (GameController.playerCoin >= GameController.astronautHirePrice && GameController.totalHiredAstronaut < GameController.maximumAstronautToHire) { //playSfx GetComponent <AudioSource> ().PlayOneShot(canBuy); //deduct the price from player's money PlayerPrefs.SetInt("PlayerCoin", GameController.playerCoin - GameController.astronautHirePrice); //increase hire counter GameController.totalHiredAstronaut++; //increase new hiring price GameController.astronautHirePrice = 1 + (GameController.totalHiredAstronaut * GameController.totalHiredAstronaut); //create small astronauts to enter the ship (you can chnage the starting point here) GameObject astro = Instantiate(astronautPrefab, new Vector3(-0.9f, 0.5f, 0.15f), Quaternion.Euler(0, 180, 0)) as GameObject; astro.name = "Astronaut"; astro.GetComponent <AstronautManager> ().dest = 1; //they need to enter the ship //update players coin in GameController class GC.GetComponent <GameController>().updatePlayersCoin(); } else { playSfx(cantBuy); } break; case "uiButton-GlobalLeaderBoard": StartCoroutine(animateButton(hitInfo.transform.gameObject)); googlePlayManager.ShowLeaderBoard(); break; } } } }