gimm-platformer-project/Assets/Scripts/tetrisManager.cs

55 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class tetrisManager : MonoBehaviour
{
public Vector3 spawnPoint;
public GameObject tetrominoSquare;
public GameObject tetrominoLine;
public GameObject tetrominoL;
public GameObject tetrominoR;
public GameObject tetrominoS;
public GameObject tetrominoT;
private int nextTetromino = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//DEBUG: Spawn a new tetromino on click.
if (Input.GetMouseButtonDown(0))
{
spawnTetromino();
}
}
void spawnTetromino()
{
nextTetromino = Random.Range(1, 6);
switch (nextTetromino)
{
case 0: //Square
Instantiate(tetrominoSquare, spawnPoint, Quaternion.identity);
break;
case 1: //Line
Instantiate(tetrominoLine, spawnPoint, Quaternion.identity);
break;
case 2: //T-piece
Instantiate(tetrominoT, spawnPoint, Quaternion.identity);
break;
default:
Instantiate(tetrominoSquare, spawnPoint, Quaternion.identity);
break;
}
}
}