using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class GameManager : MonoBehaviour { public int scorePlayer1 = 0; public int scorePlayer2 = 0; public int maxGoals = 1; public Transform player1; public Transform player2; public Transform ball; public Transform player1Initial, player2Initial, ballInitial; /* UI */ public Text scoreLabel; public Text winLabel; // Start is called before the first frame update void Start() { this.player1Initial = new GameObject().transform; this.player1Initial.position = this.player1.position; this.player1Initial.rotation = this.player1.rotation; this.player2Initial = new GameObject().transform; this.player2Initial.position = this.player2.position; this.player2Initial.rotation = this.player2.rotation; this.ballInitial = new GameObject().transform; this.ballInitial.position = this.ball.position; winLabel.transform.gameObject.SetActive(false); } // Update is called once per frame void Update() { this.scoreLabel.text = "Score: " + this.scorePlayer1 + " : " + this.scorePlayer2; if (this.scorePlayer1 >= maxGoals) { winLabel.text = "Player 1 wins the game!"; winLabel.transform.gameObject.SetActive(true); Time.timeScale = 0.0f; } if (this.scorePlayer2 >= maxGoals) { winLabel.text = "Player 2 wins the game!"; winLabel.transform.gameObject.SetActive(true); Time.timeScale = 0.0f; } if (this.scorePlayer2 >= maxGoals || this.scorePlayer1 >= maxGoals) { if (Input.GetKeyDown(KeyCode.F5)) { Time.timeScale = 1; SceneManager.LoadScene(SceneManager.GetActiveScene().name); } } } public void ResetPositions() { this.player1.position = this.player1Initial.position; this.player1.rotation = this.player1Initial.rotation; this.player1.GetComponent().velocity = Vector3.zero; this.player2.position = this.player2Initial.position; this.player2.rotation = this.player2Initial.rotation; this.player2.GetComponent().velocity = Vector3.zero; this.ball.position = this.ballInitial.position; this.ball.GetComponent().velocity = Vector3.zero; } }