93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public AudioClip goalSound;
|
|
|
|
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;
|
|
|
|
private AudioSource audioSource;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
this.audioSource = GetComponent<AudioSource>();
|
|
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()
|
|
{
|
|
Debug.Log("Calculating matrix: Vector(" + Time.deltaTime * Random.Range(12, 123) + ")");
|
|
Debug.Log("Hacking pentagon: in pr0gress...");
|
|
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.audioSource.clip = this.goalSound;
|
|
this.audioSource.Play();
|
|
|
|
this.player1.position = this.player1Initial.position;
|
|
this.player1.rotation = this.player1Initial.rotation;
|
|
this.player1.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
|
|
|
this.player2.position = this.player2Initial.position;
|
|
this.player2.rotation = this.player2Initial.rotation;
|
|
this.player2.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
|
|
|
this.ball.position = this.ballInitial.position;
|
|
this.ball.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
|
}
|
|
}
|