SHOW:
|
|
- or go back to the newest paste.
| 1 | using System.Collections; | |
| 2 | using System.Collections.Generic; | |
| 3 | using UnityEngine; | |
| 4 | using TMPro; //Wymagane do zarządzania tekstami | |
| 5 | ||
| 6 | public class PongManager : MonoBehaviour | |
| 7 | {
| |
| 8 | //czy gra trwa | |
| 9 | public bool gameRun; | |
| 10 | ||
| 11 | //Singleton odpowidzialny za zarządzanie | |
| 12 | public static PongManager instance; | |
| 13 | ||
| 14 | //punkty graczy | |
| 15 | public int player1Points; | |
| 16 | public int player2Points; | |
| 17 | ||
| 18 | //odniesienie do naszych tekstów | |
| 19 | public TMP_Text p1p; | |
| 20 | public TMP_Text p2p; | |
| 21 | ||
| 22 | //Odniesienie do piłki | |
| 23 | Ball ball; | |
| 24 | ||
| 25 | ||
| 26 | void Awake() | |
| 27 | {
| |
| 28 | //Podłączenie singletona | |
| 29 | if(instance == null) | |
| 30 | {
| |
| 31 | instance = this; | |
| 32 | } | |
| 33 | ||
| 34 | ||
| 35 | gameRun = false; | |
| 36 | player1Points = 0; | |
| 37 | player2Points = 0; | |
| 38 | UIUpdate(); | |
| 39 | //znalezienie obiektu z skryptem ball | |
| 40 | ball = FindObjectOfType<Ball>(); | |
| 41 | } | |
| 42 | ||
| 43 | void Update() | |
| 44 | {
| |
| 45 | //Uruchomienie gry | |
| 46 | if (Input.GetKeyDown(KeyCode.Space) && !gameRun) | |
| 47 | {
| |
| 48 | ball.StartGame(); | |
| 49 | gameRun = true; | |
| 50 | } | |
| 51 | } | |
| 52 | ||
| 53 | //Wyświetlanie punktów | |
| 54 | public void UIUpdate() | |
| 55 | {
| |
| 56 | p1p.text = player1Points.ToString(); | |
| 57 | p2p.text = player2Points.ToString(); | |
| 58 | } | |
| 59 | ||
| 60 | //zwiększenie ilości punktów, true dla gracza 1 a false dla gracza 2 | |
| 61 | public void UpdatePoints(bool player) | |
| 62 | {
| |
| 63 | if(player) player1Points++; | |
| 64 | else player2Points++; | |
| 65 | UIUpdate(); | |
| 66 | } | |
| 67 | } | |
| 68 |