Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class GameController : MonoBehaviour
- {
- float timeLeft = 3.0f;
- bool gameDone = false;
- // text který se zobrazí při ukončení hry
- public Text winText;
- public Text changeLevelTextT;
- public Text changeLevelTextC;
- //reference na gameobject hráč
- public GameObject playerOne;
- public GameObject playerTwo;
- //Maximální počet bodů ve scéně
- public float maxScore;
- //reference na instanci scriptu "PlayerController"
- private PlayerController pOne;
- private PlayerController pTwo;
- void Start () {
- //Inicializace referencí
- pOne = playerOne.GetComponent<PlayerController>();
- pTwo = playerTwo.GetComponent<PlayerController>();
- //Inicializace winTextu na prázdný řetězec
- winText.text = "";
- }
- void Update () {
- //Pokud jsou všechny body sesbírány true
- if (pOne.GetCount() + pTwo.GetCount() >= maxScore)
- {
- //
- gameOver();
- gameDone = true;
- //odečítání času, který byl potřeba pro dokončení posledního framu každý frame
- timeLeft -= Time.deltaTime;
- //pokud vypršel čas, přepne scénu na "Level02"
- if (timeLeft <= 0.0)
- {
- Application.LoadLevel("Level02");
- }
- //je počet bodů hráče jedna větší než hráče 2 ?
- if (pOne.GetCount() > pTwo.GetCount())
- {
- changeLevelTextT.text = "Level will be changed in: " + timeLeft + " seconds!";
- winText.text = "Player ONE win!";
- }
- //je počet bodů hráče 2 větší než hráče 1 ?
- else if (pOne.GetCount() < pTwo.GetCount())
- {
- changeLevelTextT.text = "Level will be changed in: " + timeLeft + " seconds!";
- winText.text = "Player TWO win!";
- }
- //je to remíza
- else
- {
- changeLevelTextT.text = "Level will be changed in: " + timeLeft + " seconds!";
- winText.text = "Same score.";
- }
- }
- }
- void gameOver()
- {
- if (gameDone == false)
- {
- StartCoroutine(Fade(3));
- }
- }
- private IEnumerator Fade(int coroutineTimeLeft)
- {
- for (int i = coroutineTimeLeft; i > 0; i--)
- {
- changeLevelTextC.text = "Level will be changed in: " + i + " seconds!";
- yield return new WaitForSeconds(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement