76 lines
1.7 KiB
C#
76 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Gamemaster : MonoBehaviour
|
|
{
|
|
public static Gamemaster instance;
|
|
public GameObject textPoints;
|
|
public GameObject textBalls;
|
|
public GameObject ballPrefab;
|
|
public GameObject paddle;
|
|
|
|
private int points = 0;
|
|
private int balls = 3;
|
|
|
|
private float slomoTime = -1f;
|
|
|
|
void Start()
|
|
{
|
|
Gamemaster.instance = this;
|
|
updateText();
|
|
}
|
|
|
|
void Update(){
|
|
if (slomoTime >= 0){
|
|
slomoTime += Time.deltaTime;
|
|
if (slomoTime >= 5){
|
|
Time.timeScale = 1f;
|
|
slomoTime = -1f;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void updateText(){
|
|
this.textPoints.GetComponent<TextMesh>().text = this.points.ToString();
|
|
this.textBalls.GetComponent<TextMesh>().text = this.balls.ToString();
|
|
}
|
|
|
|
public void LostBall(){
|
|
this.balls--;
|
|
if (this.balls < 0){
|
|
gameOver();
|
|
}else{
|
|
updateText();
|
|
spawnNewBall();
|
|
}
|
|
}
|
|
|
|
public void AddPoints(int points){
|
|
this.points += points;
|
|
updateText();
|
|
}
|
|
|
|
public void Slomo()
|
|
{
|
|
Time.timeScale = 0.6f;
|
|
this.slomoTime = 0;
|
|
}
|
|
|
|
public void PaddleSizePowerup()
|
|
{
|
|
var scale = this.paddle.transform.localScale;
|
|
this.paddle.transform.localScale = new Vector3(scale.x + 0.4f,scale.y,scale.z);
|
|
}
|
|
|
|
private void spawnNewBall(){
|
|
var pos = this.paddle.transform.position;
|
|
|
|
var newBall = Instantiate(this.ballPrefab,new Vector3(pos.x,1,pos.z - 1),Quaternion.identity);
|
|
}
|
|
|
|
private void gameOver(){
|
|
Debug.Log("Game over");
|
|
}
|
|
}
|