Added score and colors

This commit is contained in:
Furentes
2019-04-11 10:43:44 +02:00
parent dadc790dec
commit 3c8a40bd63
71 changed files with 8358 additions and 137 deletions

View File

@ -8,7 +8,7 @@ public class Grid : MonoBehaviour
public static int w = 10;
public static int h = 20;
public static Transform[,] grid = new Transform[w, h];
private static int count = 0;
public static int count = 0;
// Start is called before the first frame update
void Start()

View File

@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Group : MonoBehaviour
@ -9,16 +10,29 @@ public class Group : MonoBehaviour
float lastLeft = 0;
float lastRight = 0;
public static float fallSpeed = 1;
public static bool gameOver = false;
// Start is called before the first frame update
void Start()
{
TextMeshProUGUI overTxt = GameObject.FindGameObjectWithTag("Spawner").GetComponent<Spawner>().overText;
// Default position not valid? Then it's game over
if (!isValidGridPos())
{
Debug.Log("GAME OVER");
gameOver = true;
overTxt.text = "GAME OVER";
Destroy(gameObject);
}
Renderer rend;
Color randomColor = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
foreach (Transform child in transform)
{
print("Foreach loop: " + child);
rend = child.GetComponent<Renderer>();
rend.material.color = randomColor;
}
}
// Update is called once per frame

View File

@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@ -7,6 +8,9 @@ public class Spawner : MonoBehaviour
{
// Array of groups
public GameObject[] groups;
public TextMeshProUGUI score;
public TextMeshProUGUI overText;
public bool over = false;
// Constructor (called when game starts)
void Start()
@ -17,9 +21,17 @@ public class Spawner : MonoBehaviour
public void spawnNext()
{
score.text = "Score: " + Grid.count;
// Generates random index
int i = Random.Range(0, groups.Length);
// Spawn group at current spawner position
Instantiate(groups[i], transform.position, Quaternion.identity);
if (Group.gameOver) gameOver();
}
public void gameOver()
{
score.text = "GAME OVER";
}
}