Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class GameManager : MonoBehaviour
- {
- //bikin array untuk sprite2 mobil nya/
- public Sprite[] carSprites;
- //Reference to our game objects
- public GameObject playButton;
- public GameObject playerCar;
- public GameObject enemySpawner;
- public GameObject GameOverGO;
- public GameObject TimeCountdown;
- public GameObject CongratulationMessage;
- public GameObject FailedMessage;
- private GameObject GameMaster;
- public Button ReturnButton;
- public static GameManager GM;
- public int carSelected;
- private GameScore ScoreManager;
- // Use this for initialization
- private void Awake()
- {
- }
- private void Start()
- {
- GM = this;
- GameMaster = GameObject.Find("GameMaster");
- StartGamePlay();
- ScoreManager = FindObjectOfType<GameScore>();
- Debug.Log(carSelected);
- }
- // Function to update the game manager state
- public void GamePlay()
- {
- //Count the timer
- TimeCountdown.GetComponent<TimeCounter>().StartTimeCounter();
- //show the player while game start
- playerCar.GetComponent<PlayerController>().Init();
- //Start Enemy Spawner
- enemySpawner.GetComponent<EnemySpawner>().ScheduleEnemySpawner();
- }
- public void GameOver()
- {
- //Stop score when player die
- ScoreManager.scoreIncrease = false;
- //Stop enemy Spawn
- enemySpawner.GetComponent<EnemySpawner>().UnscheduleEnemySpawner();
- //Display Game Over
- GameOverGO.SetActive(true);
- // ***** tombol return muncul kalo mati (cuma buat debug) *****
- ReturnButton.gameObject.SetActive(true);
- // ***** Kalau dapet highscore, munculin kata2 selamat. *****
- if (ScoreManager.scoreCount >= ScoreManager.highScoreCount)
- {
- CongratulationMessage.SetActive(true);
- // ***** sekalian write highsscore nya ke playerpref *****
- PlayerPrefs.SetFloat("HighScore", ScoreManager.highScoreCount);
- FailedMessage.SetActive(false);
- }
- else
- {
- FailedMessage.SetActive(true);
- CongratulationMessage.SetActive(false);
- }
- //Change game manager state to opening state
- Invoke("ChangeToMainMenu", 8f);
- TimeCountdown.GetComponent<TimeCounter>().StopTimeCounter();
- }
- public void StartGamePlay()
- {
- carSelected = GameMaster.GetComponent<GameMaster>().carSelected;
- playerCar.GetComponent<SpriteRenderer>().sprite = carSprites[carSelected];
- GamePlay();
- }
- //Function to change game manager state to opening state
- public void ChangeToMainMenu()
- {
- Application.LoadLevel("mainmenu");
- }
- }
Add Comment
Please, Sign In to add comment