mirror of
https://github.com/p08dev/Tetrys.git
synced 2026-06-19 13:13:50 +02:00
Added restart [F1] and exit game [ESC]
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Spawner : MonoBehaviour
|
public class Spawner : MonoBehaviour
|
||||||
@ -15,10 +16,25 @@ public class Spawner : MonoBehaviour
|
|||||||
// Constructor (called when game starts)
|
// Constructor (called when game starts)
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
Group.fallSpeed = 1f;
|
||||||
|
Grid.count = 0;
|
||||||
|
score.text = "Score: " + Grid.count;
|
||||||
// Spawn initial group
|
// Spawn initial group
|
||||||
spawnNext();
|
spawnNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (Input.GetKey(KeyCode.Escape))
|
||||||
|
{
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
|
if (Input.GetKey(KeyCode.F1))
|
||||||
|
{
|
||||||
|
restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void spawnNext()
|
public void spawnNext()
|
||||||
{
|
{
|
||||||
score.text = "Score: " + Grid.count;
|
score.text = "Score: " + Grid.count;
|
||||||
@ -26,12 +42,10 @@ public class Spawner : MonoBehaviour
|
|||||||
int i = Random.Range(0, groups.Length);
|
int i = Random.Range(0, groups.Length);
|
||||||
// Spawn group at current spawner position
|
// Spawn group at current spawner position
|
||||||
Instantiate(groups[i], transform.position, Quaternion.identity);
|
Instantiate(groups[i], transform.position, Quaternion.identity);
|
||||||
|
|
||||||
if (Group.gameOver) gameOver();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameOver()
|
void restart()
|
||||||
{
|
{
|
||||||
score.text = "GAME OVER";
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user