Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class GameControl : MonoBehaviour
- {
- public static GameControl instance; //to make function be accessible from other class.
- public GameObject gameOverMenu, playBtn, pauseBtn;
- public Text scoreText, bestScore, gameOverText, scoreTextB;
- public bool gameOver = false;
- public float scrollSpeedLand = -1.25f;
- public float scrollSpeedBg = -0.0625f;
- public float scrollSpeedCloud = -0.0125f;
- private int score = 0;
- private bool paused = false;
- private bool mainMenu, restart = false;
- void Start()
- {
- playBtn.gameObject.SetActive(false);
- pauseBtn.gameObject.SetActive(true);
- }
- void Awake()
- {
- //if start game and find no instance of gameControl, then this is the instance
- if (instance == null)
- instance = this;
- else if (instance != this)
- Destroy(gameObject);
- }
- public void BirdDied()
- {
- gameOverMenu.gameObject.SetActive(true);
- pauseBtn.gameObject.SetActive(false);
- gameOverText.text = "Game Over";
- gameOver = true;
- if (score > Main.instance.GetHighScore())
- {
- Main.instance.SetHighScore(score);
- }
- scoreText.gameObject.SetActive(false);
- scoreTextB.text = "" + score.ToString();
- bestScore.text = "" + Main.instance.GetHighScore();
- }
- public void BirdScored()
- {
- if (gameOver == true)
- return;
- else if (gameOver == false)
- {
- score++;
- scoreText.text = "Score: " + score.ToString();
- }
- }
- public void restartGame()
- {
- restart = true;
- if(gameOver == true && restart == true)
- {
- AdsManager.instance.showVideo();
- }
- }
- public void MainMenu()
- {
- mainMenu = true;
- if (gameOver == true && mainMenu == true)
- {
- AdsManager.instance.showVideo();
- }
- }
- public void LoadLevel()
- {
- if(gameOver == true && restart == true)
- {
- SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
- }
- else if(gameOver == true && mainMenu == true)
- {
- SceneManager.LoadScene("Main");
- }
- }
- public void pauseGame()
- {
- Time.timeScale = 0;
- paused = true;
- pauseBtn.gameObject.SetActive(false);
- playBtn.gameObject.SetActive(true);
- }
- public void continueGame()
- {
- if (paused == true)
- {
- Time.timeScale = 1;
- playBtn.gameObject.SetActive(false);
- pauseBtn.gameObject.SetActive(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement